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

19 views
Skip to first unread message

Samir Kothawade

unread,
Apr 21, 2020, 1:31:47 AM4/21/20
to Ansible Project
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

Abhijeet Kasurde

unread,
Apr 21, 2020, 2:16:03 AM4/21/20
to ansible...@googlegroups.com
How about writing a shell script with ansible-playbook command, and triggering that every 30 minutes using crontab.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/43514f7d-40fb-4262-b7de-1a7921edbc0a%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Karl Auer

unread,
Apr 21, 2020, 4:54:09 AM4/21/20
to ansible-project
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.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/43514f7d-40fb-4262-b7de-1a7921edbc0a%40googlegroups.com.


--

Karl Auer { manager, systems support }
P: 1300 759 975
E: ka...@2pisoftware.com
2pisoftware.com

GPG/PGP : DF6A 43E5 FB9D D884 C6CA CD7F 5278 212D E80F C107
Previous: 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E
Reply all
Reply to author
Forward
0 new messages