ansible 使用ping模塊和時間同步模塊


命令格式

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM