[deyu1@kvm19 ansible]$ vim cron.yml [deyu1@kvm19 ansible]$ cat cron.yml --- - name: cron test hosts: test tasks: - ansible.builtin.cron: name: "create a cron job for deyu1" weekday: '2' minute: '0' hour: '12' user: deyu1 job: 'echo "My CRON_TEST"'
[deyu1@kvm19 ansible]$ ansible-playbook cron.yml PLAY [cron test] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [kvm12] TASK [cron] ******************************************************************** changed: [kvm12] PLAY RECAP ********************************************************************* kvm12: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[deyu1@kvm19 ansible]$ ansible test -m shell -a "crontab -u deyu1 -l" kvm12 | CHANGED | rc=0 >> #Ansible: create a cron job for deyu1 0 12 * * 2 echo "My CRON_TEST"