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="[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
- 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