要求:linux CentOS release 6.8 (Final)
兩臺機器:192.168.1.2 192.168.1.3
創建一個腳本放在/tmp目錄下
vim /tmp/test.sh
#!/bin/bash
echo `date` > /tmp/a.txt
2. 分發到各個節點上
ansible testhost -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
3.執行節點腳本
ansible testhost -m shell -a "/tmp/test.sh"
4.ansible 添加crontab定時任務
添加crontab
ansible testhost -m cron -a "name='test cron' job='/bin/touch /tmp/12.txt' weekday=6"
tip:分鐘minute 小時hour 日期day 月份month
刪除crontab
ansible testhost -m cron -a "name='test cron' state=absent"
5.ansible rpm包 服務管理
安裝httpd
ansible testhost -m yum -a "name=httpd"
name後可以加入state=installed
管理httpd 設置開機啓動
ansible testhost -m service -a "name=httpd state=started enabled=yes"
文檔使用
ansible-doc -l 列出所有的模塊
ansible-doc cron 查看指定模塊的文檔