Let's assume I have a hostgroup of 6 hosts and I need to run a playbook (play1) two times in sequence for different hosts in that group because of depenencies between some hosts.
I'd like to gather information within both plays and pass that information further.
In a last step I'd like to reuse the previously collected information in order to create a summary over all hosts (in both plays 1_a and 1_b); here for debugging (later I'd
like to use that information to create an html report with a Jinja2 templating).
The problem I have is the information in the debug messages are not per host. It seems it stores just the output from one host and reuses it for all others in the
inventory in the last play (see sample output of the report_comment variable below -> just one of those 6 servers had that exception).
I'm not sure if using the set_stats module is the best way to reach what I'd like?
Or would it be better to store the information in temp. files on localhost and read the information in the last play?
Any ideas or suggestions how to reach my goal would be much appreciated!
Workflow Template
|-------------| |-------------| |-------------|
| play1_a | ---> | play1_b | ---> | summary |
|-------------| |-------------| |-------------|
play1_a:
---
hosts: server1
tasks:
- name: test powershell
block:
- name: Search For Windows Udpates
ansible.windows.win_updates:
reboot: no
state: searched
register: list_of_updates
- name: Pass list_of_updates to next job
ansible.builtin.set_stats:
data:
listofupdates: "{{ list_of_updates }}"
rescue:
- name: Catch Exception
ansible.builtin.set_fact:
report_comment: "{{ list_of_updates.msg }}"
ignore_errors: yes
when: '"Exception" in list_of_updates.msg'
- name: Pass Exception for Summary
ansible.builtin.set_stats:
data:
reportcomment: "{{ report_comment }}"
play1_b:
---
hosts: hostgroup:!server1
tasks:
- name: test powershell
block:
- name: Search For Windows Udpates
ansible.windows.win_updates:
reboot: no
state: searched
register: list_of_updates
- name: Pass list_of_updates to next job
ansible.builtin.set_stats:
data:
listofupdates: "{{ list_of_updates }}"
rescue:
- name: Catch Exception
ansible.builtin.set_fact:
report_comment: "{{ list_of_updates.msg }}"
ignore_errors: yes
when: '"Exception" in list_of_updates.msg'
- name: Pass Exception for Summary
ansible.builtin.set_stats:
data:
reportcomment: "{{ report_comment }}"
summary (Debugging):
---
- hosts: hostgroup
vars:
list_of_updates: "{{ listofupdates }}"
report_comment: "{{ reportcomment }}"
tasks:
- name: print output List of Updates
debug:
msg: "{{ list_of_updates}}"
- name: print output Report Comment
debug:
msg: "{{ report_comment }}"
Sample Output of report_comment variable:
TASK [print output Report Comment] *********************************************
ok: [server1] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}
ok: [server2] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}
ok: [server3] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}
ok: [server4] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}
ok: [server5] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}
ok: [server6] => {
"msg": "Searching for updates: Exception from HRESULT: 0x80072EFD - Unknown WUA HRESULT 2147954429 (UNKNOWN 80072EFD)"
}