Ansible 常用模块

Ansible 常用模块

command:在远程主机执行命令,默认模块,可忽略 -m 选项
ansible server -m command -a 'systemctl restart httpd'
shell:和command模块相似,用shell执行命令
ansible server -m shell -a 'systemctl start httpd'
scrip:在远程主机上执行ansible主机上的脚本,且不需要将脚本复制到被执行的远程主机上
ansible server -m script -a '/root/Shell/script.sh'
copy:从主控端复制文件到客户端
ansible server -m copy -a 'src=/root/guoqiang.sh dest=/root/'
# backup=yes:备份

ansible all -m copy -a 'content="hello\nthanks\n" dest=/root/guoqiang.sh'
# content:生成自定义内容写入guoqiang.sh文件中
fetch:从客户端取文件主控端,与copy相关,目前可以先tar
nsible server -m fetch -a 'src=/root/guoqiang.sh dest=/data'
file:设置文件属性
ansible server -m file -a 'path=/root/guoqiang.sh mode=777'

# 创建一个新的空文件
ansible server -m file -a 'path=/data/readme.sh state=touch'

# 创建一个文件夹
ansible server -m file -a 'path=/data state=directory'

# 生成软件链接文件
ansible server -m file -a 'src=/etc/fstab path=/data/fstab.link state=link'

# 删除一个文件
ansible server -m file -a 'path=/data/readme.sh state=absent'

# 删除一个文件夹
ansible server -m file -a 'path=/data state=absent'

# 删除一个软连接文件
 ansible server -m file -a 'path=/fstab.link state=absent'
hostname:管理主机名
 ansible 172.16.7.130 -m hostname -a 'name=ansible-slave'
#将172.16.7.130节点的主机名修改为ansible-slave
yum:管理包
# 安装
ansible server -m yum -a 'name=httpd state=installed'

# 查看已经安装的包
ansible server -m yum -a 'list=installed'

# 卸载
 ansible server -m yum -a 'name=httpd state=removed'
service:管理服务
ansible server -m service -a 'name=httpd state=started enabled=yes'

#启动:started
#重启:restarted
#停止:stopped
#开机自启:enabled=yes
#取消开机自启:enabled=no
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值