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