Help needed to spedup the execution of playbook using aync

36 views
Skip to first unread message

Saravanan

unread,
Nov 12, 2018, 1:04:43 PM11/12/18
to Ansible Project
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

---
- 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="ans...@localhost.com"
                    to="som...@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

    - 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  

Saravanan Ponnusamy

unread,
Nov 12, 2018, 3:25:41 PM11/12/18
to ansible...@googlegroups.com
Hi Ansible Expers,
Can you please share your valuable suggestions/ inputs to improve the performance of the playbook?
--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/088c8c9f-a7e1-43ed-8104-df4db7ca6d49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Saravanan

unread,
Nov 12, 2018, 7:30:44 PM11/12/18
to Ansible Project
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?
Hi Ansible Expers,
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages