命令格式
ansible 主機清單中IP或分組名稱 -m 模塊
ping模塊應用
ansible 192.168.1.6 -m ping 或者 ansible new-machine -m ping
輸出結果:
[root@server ansible]# ansible new-machine -m ping
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
192.168.1.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[root@server ansible]#
ansible 192.168.1.6 -m cron -a 'name="test cron1" job="nepdate time1.aliyun.com" monute=0 hour=*/1'
[root@server ansible]# ansible 192.168.1.6 -m cron -a 'name="test cron1" job="ntpdate time1.aliyun.com" minute=0 hour=*/1'
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
192.168.1.6 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"envs": [],
"jobs": [
"test cron1"
]
}
目標機器查看crontab -l
[root@client ~]# crontab -l
#Ansible: test cron1
0 */1 * * * ntpdate time1.aliyun.com
[root@client ~]#
注意事項:
國內的話,選擇阿里或騰訊雲的時鍾源
time.pool.aliyun.com
time1.cloud.tencent.com
海外的話,選擇微軟或者google的時鍾源
time.windows.com
time1.google.com
參考鏈接:
https://docs.ansible.com/ansible/latest/modules/cron_module.html#cron-module