Ansible常用命令

-------------old

# 检查主机连接
# ansible caoguo -m ping

# 执行远程命令
# ansible caoguo -m command -a 'uptime'

# 执行主控端脚本
# ansible caoguo -m script -a '/etc/ansible/script/test.sh'

# 执行远程主机的脚本
# ansible caoguo -m shell -a 'ps aux|grep zabbix'

# 类似shell
# ansible caoguo -m raw -a "ps aux|grep zabbix|awk '{print \$2}'"

# 创建软链接
# ansible caoguo -m file -a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link"

# 删除软链接
# ansible caoguo -m file -a "path=/tmp/resolv.conf state=absent"

# 复制文件到远程服务器
# ansible caoguo -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"

------------new

批量后台启动脚本并输出到日志

ansible IPaddress -m command -a 'nohup python -u /home/ceshi/sichuan/xl.py 0 > out.log 2>&1 &'
批量复制文件到test3组服务器
ansible test3 -m copy -a 'src=/root/qd/shandong dest=/home/ceshi/'

批量删除test5组服务器的某个文件

ansible  test5 -m shell -a "rm -rf /home/ceshi/anhui" -i '/etc/ansible/hosts'










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值