# How to schedule a task which should be run after every 30 mins

**URL:** <https://forum.ansible.com/t/how-to-schedule-a-task-which-should-be-run-after-every-30-mins/32743>\
**Category:** Ansible Project\
**Created:** [April 21, 2020, 5:31am UTC](https://forum.ansible.com/t/how-to-schedule-a-task-which-should-be-run-after-every-30-mins/32743 "2020-04-21T05:31:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 21, 2020, 5:31am UTC](https://forum.ansible.com/t/how-to-schedule-a-task-which-should-be-run-after-every-30-mins/32743/1 "2020-04-21T05:31:47Z")

</div>

Hi,

I want to execute specified task in ansible playbook after every 30 mins. Task is not just a command, so “at” module does not work in my case or may be I am not doing it in proper way :

Here is my play book. Playbook below runs correctly for single time. I want to collect the stats after every 30 mins, so how should I do that… Can you guys please suggest solution ?

- hosts: zmr  
gather\_facts: no  
vars:  
date: “{{ lookup(‘pipe’, ‘date +%Y%m%d-%H%M’) }}”  
tasks:
- name: set the winsize  
shell: stty cols 5000 rows 5000
- name: Get the debug status  
ignore\_errors: yes  
expect:  
command: /opt/wishu/ZMR\_Platform/bin/go\_zmr\_cli  
timeout: 5  
responses:  
(._)Username:(._): “admin”  
(._)Password:(._): “admin”  
(._)ZMR\>(._): display debug info PP ip 192.168.30.26 port 8686  
(._):(._): " q"  
timeout: 30  
register: stats
- local\_action: copy content=“{{ stats\_.stdout}}” dest=“/home/sam/stats\_{{ lookup(‘pipe’, ‘date +%Y%m%d-%H%M’) }}.txt”  
ignore\_errors: yes

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [April 21, 2020, 6:15am UTC](https://forum.ansible.com/t/how-to-schedule-a-task-which-should-be-run-after-every-30-mins/32743/2 "2020-04-21T06:15:26Z")

</div>

How about writing a shell script with ansible-playbook command, and triggering that every 30 minutes using crontab.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 21, 2020, 8:53am UTC](https://forum.ansible.com/t/how-to-schedule-a-task-which-should-be-run-after-every-30-mins/32743/3 "2020-04-21T08:53:41Z")

</div>

Create a script (e.g. in bash) that does everything you want to do, including run Ansible.

Then create a cron-job which runs that script at the intervals you desire.

Regards, K.
