Ansible —- 安装配置:http://www.01wneo.xin/?p=451
yum install ansible* -y 安装 ansible 软件
--version 查看 Ansible 软件版本信息
ansible-doc -l | wc -l 统计 ansible 命令个数
ansible-doc yum 查看 yum(某个) 命令的用法
ansible -k web -m ping ping ansible 定义的服务器信息;需要配置 vim ansible.cfg host_key_checking = False # 解开此行注释,不检查主机的 key
ansible web -m command -a "date" ansible 是并行的 -m command 是默认参数可以不加
ansible -i /etc/ansible/list.txt web -m command -a "date" 引用主机列表文件 -m command 是默认参数可以不加
ansible 192.168.1.2 -m shell -a "rm -rf /tmp/*" 使用 shell 模块执行命令
ansible -Cvvv 192.168.1.2 -m shell -a "rm -rf /tmp/*" 显示执行命令详细过程
ansible all -m shell -a "rm -rf /tmp/*" 删除所有服务器 tmp 目录下的所有文件,但不包括.开头的文件
ansible all -m shell -a "ls /tmp/ | grep -v ansible | wc -l;date;df -h"
可以使用多个命令组合,使用分号隔开
ansible all -m shell -a "echo '0 0 * * * /usr/sbin/ntpdate pool.ntp.org >>/tmp/ntp.log 2>2>&1' >>/var/spool/cron/root;crontab -l"
批量添加 linux 任务计划
ansible all -m shell -a "yum install httpd;service httpd restart;ps -ef | grep httpd"
批量安装 Apache,启动后查看 Apache 进程
ansible all -m shell -a "sed -i '/ntpdate/s/0 0/0 1/g' /var/spool/cron/root;crontab -l"
批量修改任务计划
ansible all -m shell -a "sed -i '/ntpdate/d' /var/spool/cron/root;crontab -l"
批量删除任务计划