# Help needed to spedup the execution of playbook using aync

**URL:** <https://forum.ansible.com/t/help-needed-to-spedup-the-execution-of-playbook-using-aync/29011>\
**Category:** Ansible Project\
**Tags:** awx\
**Created:** [November 12, 2018, 6:04pm UTC](https://forum.ansible.com/t/help-needed-to-spedup-the-execution-of-playbook-using-aync/29011 "2018-11-12T18:04:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [November 12, 2018, 6:04pm UTC](https://forum.ansible.com/t/help-needed-to-spedup-the-execution-of-playbook-using-aync/29011/1 "2018-11-12T18:04:43Z")

</div>

Hi Team,  
Herewith I am sharing my core playbook and another yaml playbook used for iteration to get the apache server status, storing them to a file. This playbook takes longer time to complete the task on all hosts. To speedup he execution, I would like to include async in the play.  
Please check these files and share your suggestion on how best we can implement async to speed up the playbook execution.

**apache\_monitoring.yaml**

```auto
---
- name: Apache server check
  gather_facts: no
  hosts: 127.0.0.1
  strategy: free

  tasks:
    - name: Create csv file and html file
      file:
        path: "{{ item }}"
        state: touch
      delegae_to: localhost
      become_user: awx
      become: no
      with_items:
        - /tmp/apache.csv
        - /tmp/apache.html

    - include_vars: apache_sever_list.yaml

    - include_tasks: apache_task.yaml
      with_items: '{{ apacheSevers }}'

    - name: Run the csv2html script
      shell: |
        echo "<h3>List of failed Apache servers</h3>"
        echo "<table>" ;
        echo "<table><tr><th>Hostname</th><th>Port</th></tr>"
        while read INPUT; do
        echo "<tr><td>${INPUT//,/</td><td>}</td></tr>";
        done < /tmp/apache.csv
        echo "</table>"
      delegae_to: localhost
      become_user: awx
      become: no        

    - name: append
      lineinfile:
        dest: /tmp/apache.html
        line: "{{ output.stdout }}"
        insertafter: EOF
      delegae_to: localhost
      become_user: awx
      become: no

    - name: Send out email
      local_action: mail
                    host='127.0.0.1'
                    port=25
                    subject="Apache servers not running"
                    body="{{ lookup('file', '/tmp/apache.html') }}"
                    from="[ansible@localhost.com](mailto:ansible@localhost.com)"
                    to="[someone@email.com](mailto:someone@email.com)"
                    secure="never"
                    subtype="html"
                    charset=utf8
      delegae_to: localhost
      become_user: awx
      become: no
      run_once: true

    - name: Clear csv file and html file
      file:
        path: "{{ item }}"
        state: touch
      delegae_to: localhost
      become_user: awx
      become: no     
      with_items:
        - /tmp/apache.csv
        - /tmp/apache.html

```

**apche\_task.yaml**

```auto
    - name: Check the apache server status
      uri:
        url: "{{ item.hostname }}:{{ item.port }}"
        method: GET
        status_code: 200
        body_format: raw
        follow_redirects: all
        return_content: yes
        validate_certs: no
        force: yes
      delegae_to: localhost
      become_user: awx
      become: no

    - name: append output to file
      lineinfile:
        dest: /tmp/apache.csv
        line: "{{ item.hostname }},{{ item.port }}"
        insertafter: EOF
      delegae_to: localhost
      become_user: awx
      become: no  

```

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [November 12, 2018, 8:25pm UTC](https://forum.ansible.com/t/help-needed-to-spedup-the-execution-of-playbook-using-aync/29011/2 "2018-11-12T20:25:28Z")

</div>

Hi Ansible Expers,  
Can you please share your valuable suggestions/ inputs to improve the performance of the playbook?

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [November 13, 2018, 12:30am UTC](https://forum.ansible.com/t/help-needed-to-spedup-the-execution-of-playbook-using-aync/29011/3 "2018-11-13T00:30:44Z")

</div>

Tested the async feature having only one task in the apache\_task.yaml file without collecting the result to csv file and it was successful.  
Can you help to check the server status and append to a file in a single task?
