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

**URL:** <https://forum.ansible.com/t/new-to-ansible-so-please-be-gentle-running-ansible-playbook-via-crontab/30338>\
**Category:** Ansible Project\
**Created:** [May 15, 2019, 11:30am UTC](https://forum.ansible.com/t/new-to-ansible-so-please-be-gentle-running-ansible-playbook-via-crontab/30338 "2019-05-15T11:30:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tariq\_Hasan](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tariq\_Hasan](https://forum.ansible.com/u/Tariq_Hasan)\
**Post date:** [May 15, 2019, 11:30am UTC](https://forum.ansible.com/t/new-to-ansible-so-please-be-gentle-running-ansible-playbook-via-crontab/30338/1 "2019-05-15T11:30:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 15, 2019, 11:39am UTC](https://forum.ansible.com/t/new-to-ansible-so-please-be-gentle-running-ansible-playbook-via-crontab/30338/2 "2019-05-15T11:39:06Z")

</div>

what version of ansible are you on?

Regardless, you should use the yum module [https://docs.ansible.com/ansible/latest/modules/yum\_module.html](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](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.

---

<div class="post-metadata">

**Author:** ![Tariq\_Hasan](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tariq\_Hasan](https://forum.ansible.com/u/Tariq_Hasan)\
**Post date:** [May 15, 2019, 11:53am UTC](https://forum.ansible.com/t/new-to-ansible-so-please-be-gentle-running-ansible-playbook-via-crontab/30338/3 "2019-05-15T11:53:42Z")

</div>

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