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

20 views
Skip to first unread message

Tariq Hasan

unread,
May 15, 2019, 7:30:06 AM5/15/19
to Ansible Project
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

Jonathan Lozada De La Matta

unread,
May 15, 2019, 7:39:27 AM5/15/19
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/60f5b636-a28d-4c08-b37b-a268daa3b89b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Jonathan Cha'gara Lozada De La Matta

He / Him / His

Automation Practice

Senior Automation Consultant & Automation CoP Manager

Red Hat


 

Message has been deleted

Tariq Hasan

unread,
May 15, 2019, 7:53:42 AM5/15/19
to Ansible Project
2.7.5
I'll look at the links you sent.
Thanks
Reply all
Reply to author
Forward
0 new messages