1、新增一个定时任务:
ansible all -m cron -a "name=check minute=5 job='pwd'"
![img_4b95538783c656818bb0dfd3f9e73136.png](https://i-blog.csdnimg.cn/blog_migrate/3bbc450d6da850a9986c6c010ce387a6.png)
image.png
2、删除定时任务:
ansible all -m cron -a "name=check state=absent"
3、把这个定时任务存放在/etc/cron.d/目录下的某一个自定义文件中:
ansible all -m cron -a "name=check minute=5 job='pwd' user='root' cron_file='testcronfile'"
![img_b3cc0f0c8c263431a0ab2dee6bdc92a4.png](https://i-blog.csdnimg.cn/blog_migrate/b59e48bd27ae339b05a84d52ab88b834.png)
image.png
4、定时任务的参数还包括:day,hour,month,weekday,state(任务启用或停止),reboot(重启后是否需要执行,默认为否)
5、修改主机名字:hostname
ansible 172.16.52.245 -m hostname -a "name=ansible-test245"