@Dick your solution takes 64 seconds for starting and checking for 
successful telnet if each of the three scripts has 30 seconds sleep time. 

With the below approach, it takes only half the time i.e 35 seconds to 
complete everything. 

cat main.yml

---

- name: Starting services
  gather_facts: false
  hosts: localhost
  tasks:

    - include_tasks: "newinternal.yml"
      loop:
        -  ~/startapp1.sh 4443
        -  ~/startapp2.sh 4445
        -  ~/startapp3.sh 4447

    - name: Pause for 32 seconds to check telnet
      pause:
        seconds: 32

    - include_tasks: "waitnewinternal.yml"
      loop:
        -  ~/startapp1.sh 4443
        -  ~/startapp2.sh 4445
        -  ~/startapp3.sh 4447

cat  newinternal.yml

   - shell: "{{ item.split()[0] }}"
     async: 600
     poll: 0

cat waitnewinternal.yml

   - name: Starting multiple wait_for tasks
     wait_for:
       host: localhost
       port: "{{ item.split()[1] }}"
       timeout: 43
     register: foo
     async: 600
     poll: 0
     changed_when: false

   - name: Collecting status of wait_for tasks
     async_status:
       jid: "{{ foo.ansible_job_id }}"
     register: jobs
     until: jobs.finished
     delay: 1
     retries: 600

Considering the solution you provided is async without bottlenecks I have 
the below 2 queries:

1. Can you please explain why the difference of half the time?
2. Can your solution be optimized so it also takes less than 40 seconds 
which makes sense. My solution is not ideal as the 32 seconds of sleep is 
not definitive and will vary from environment to environment. 

On Tuesday, June 21, 2022 at 12:42:29 AM UTC+5:30 [email protected] wrote:

> On Mon, 20 Jun 2022 at 21:06, Mohtashim S <[email protected]> wrote:
> >
> > @Dick under ` - name: Starting multiple wait_for tasks` -> i do not have 
> a loop ` loop: "{{ ports }}"` as my loop is in `main.yml` outer yml
> >
> > Thus, i get the following error:
> >
> > TASK [Collecting status of wait_for tasks] 
> *********************************************************************************************************************************************************************
> > task path: /root/newinternal.yml:17
> > fatal: [localhost]: FAILED! => {
> > "msg": "'dict object' has no attribute 'results'"
> > }
> >
> > Can you please suggest?
>
> I can't do everything for you.
> Look at the tasks/logic of the (fully working) playbook that I
> provided and adapt it to your situation.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5540f136-06de-4275-a941-5cd7e4dd7818n%40googlegroups.com.

Reply via email to