New to ansible so please be gentle - running ansible-playbook via crontab

Hi

Please find below my playbook

  • name: Patch the server and Reboot
    hosts: tariq-test
    tasks:

  • name: Patch the server
    become: yes
    become_user: root
    tags: Patch
    shell: “yum -y update”
    exclude: kernel*,mongo*
    register: patchresult

  • name: Reboot the server
    tags: reboot
    become: yes
    become_user: root
    shell: “sleep 5 && reboot”
    async: 1
    poll: 0

  • name: Wait for the reboot and reconnect
    wait_for:
    port: 22
    host: ‘{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}’
    search_regex: OpenSSH
    delay: 10
    timeout: 60
    connection: local

  • name: Check the Uptime of the servers
    shell: “uptime”
    register: Uptime

  • debug: var=Uptime

I would like to able to run this via cron, but whenever I try, the job starts, according to the cron log, but doesn’t actually do anything.
I’ve tried allsorts, nothing works.

07 11 * * * /bin/ansible-playbook /etc/ansible/playbooks/reboot.yml >> /var/tmp/reboot.log >/dev/null 2>&1
06 12 * * * if ! out=ansible-playbook /etc/ansible/playbooks/reboot.yml; then echo $out; fi
14 12 * * * /bin/ansible-playbook /etc/ansible/playbooks/reboot.yml >> /var/tmp/reboot.log >/dev/null 2>&1

Any ideas please?
Regards
Tariq

what version of ansible are you on?

Regardless, you should use the yum module https://docs.ansible.com/ansible/latest/modules/yum_module.html and ( if on 2.7) https://docs.ansible.com/ansible/latest/modules/reboot_module.html. Should be able to work better and handled everything you described. I suggest you make sure it actually works first.

2.7.5
I’ll look at the links you sent.
Thanks