命令格式

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

相关文章:

  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-10-03
  • 2021-05-19
猜你喜欢
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2022-12-23
  • 2021-08-12
相关资源
相似解决方案