ansible Loop help

50 views
Skip to first unread message

Thirumalai Raja A

unread,
May 2, 2024, 7:36:48 AM5/2/24
to ansible...@googlegroups.com
HI TEAM,

below is my task to check the job completed status for the set of ips, and for an ip approximately taking 15 mins to get the status. if i am having 5 number of ips its taking too long to complete my task.

so i am looking for parallel options to check for this particular task. is is passible to do that?
if yes can anyone guide me pls.


    - name: PPS Playbook Status
      pps_check:
        vm_ip: "{{ item }}"
      register: status_check
      with_items: "{{available_ips}}"
      tags:
        - pps-status

John Harmon

unread,
May 8, 2024, 6:56:14 PM5/8/24
to Ansible Project
You mean something like this?

    - name: Run status check 

      pps_check:
        vm_ip: "{{ item }}"
        url: "https://bldrapp.sys.comcast.net/api/v3/hosts/status?host-list="
      register: status_check
      with_items: "{{ available_ips }}"
      async: 900  # Adjust the timeout based on the expected maximum time to complete the task (15 minutes)
      poll: 0
      tags:
        - pps-status

    - name: Wait for all tasks to complete
      async_status:
        jid: "{{ item.ansible_job_id }}"
      register: job_result
      until: job_result.finished
      retries: 30  # Adjust as needed
      delay: 60    # Adjust as needed
      with_items: "{{ status_check.results }}"
      tags:
        - pps-status

    - name: Gather results
      set_fact:
        all_results: "{{ all_results | default([]) + [item] }}"
      loop: "{{ job_result.results }}"
      tags:
        - pps-status
Reply all
Reply to author
Forward
0 new messages