课时4 Ansible常见企业级应用模块实战

ansible-doc 模块名! 帮助文档
在这里插入图片描述
copy模块

将控制端的文件复制到被控制端
ansible all -m copy -a ‘src=/root/ansible/selinux dest=/etc/selinux/config backup=yes’
copy属性:
backup:复制前备份该文件
mode:修改权限
owner:修改拥有者

把内容复制到该文件
ansible all -m copy ‘content=“helo” dest=/data/f2’

··········································································
fetch模块

把远程的主机文件抓取到本机控制端,而且只能是一个文件,具有局限性
fetch:
ansilbe all -m fetch -a ‘src=/root/a.sh dest=/data/scripts’
tar压缩打包命令:tar zcvf/Jcf log.tar.xz /var/log/*.log
预览tar包,tar tvf 包名
···········································································
file模块

ansible all -m file -a ‘name=/data/f3 state=touch’ 创建空文件
ansible all -m file -a ‘name=/data/f3 state=directory’ 创建文件夹
ansible all -m file -a ‘src=/etc/fstab name=/data/f3 state=link’ 创建软连接
ansible all -m file -a ‘name=/data/f3 state=absent’ 删除
··················································································
在这里插入图片描述
hostname模块

hostname:不切合实际,不可能每个主机名都一样
C7修改了/etc/hostname后,也有修改/etc/hosts回环地址的主机名
C6修改主机名:/etc/sysconfig/network
··················································································
cron模块

远程定时任务:ansible all -m cron -a ‘minute=* weekday=1,3,5 job="/usr/bin/wall FBI warning" name=warningcron’
远程禁用定时任务:ansible all -m cron -a ‘disabled=yes job="/usr/bin/wall FBI warning" name=warningcron’
远程启用定时任务:ansible all -m cron -a ‘disabled=no job="/usr/bin/wall FBI warning" name=warningcron’
删除定时任务:ansible all -m cron -a ‘state=absent job="/usr/bin/wall FBI warning" name=warningcron’
··························································································
yum模块

ansible all -m yum -a 'name=vsftpd ’ 默认是安装
ansible all -m yum -a ‘name=httpd,vsftpd state=latest/installed/present’ 安装多个包
ansible all -m yum -a ‘name=httpd state=absent/removed’ 删除
禁用yum源仓库,在yum源配置文件中enabled=0
yum源list清单情况(安装):ansible all -m yum -a ‘list=installed’
单独一个rpm包安装:
1.把包用ansible all -m copy…复制到各个被控制端
2.在用yum模块安装
忽略gpg检查:disabled_gpg_check=yes
安装时更新yum源仓库:update_cache=yes
ansible all -m yum -a ‘name=vsftpd update_cache=yes’
················yum clean all ;yum repolist
·················································································

在这里插入图片描述
service模块
state:started/stopped/restarted/reloaded
服务停止:ansible all -m service -a ‘name=httpd state=stopped’
开机启动服务:enabled=yes
C7上查看vdftpd开机自启动项:systemctl is-enabled vsftpd
systemctl status vsftpd
··············································································
user模块
添加用户:ansible all -m user -a ‘name=nginx shell=/sbin/nologin system=yes home=/var/nginx groups=root,bin’
system是否为系统账号 groups附组 group 主组 uid等 comment=“xxxx” 描述 remove删除家目录
删除用户:ansible all -m user -a ‘name=nginx state=absent remove=yes’
·································································
group模块
添加组:ansible all -m group -a ‘name=nginx system=yes gid=80’
删除组:ansible all -m group -a ‘name=nginx state=absent’

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值