Good day!
I guess I'm fond of creating reports from debug output. Well, actually, I have a business case for doing so. I have a couple of playbooks that I've set up to create report:
playbook 1 -
---
- hosts: host1
gather_facts: false
become: yes
tasks:
- name: yum_command
shell: rpm -qa|sort -n
register: packages
- debug:
var: packages
- local_action:
module: copy
content: |
{% for host in ansible_play_hosts %}
{{ host }}:
The following packages are installed
{{ hostvars[host]['packages']['stdout']|default("None", true) }}
{% endfor -%}
dest: "/tmp/installed.txt"
run_once: yes
tags:
- report
playbook 2 -
---
- hosts: host1
gather_facts: false
become: yes
tasks:
- name: yum_command
yum:
list=updates
register: packages
- debug:
var: packages
- debug: var=item
with_items: "{{packages|json_query(jsonquery)}}"
vars:
jsonquery: "results[?name!='null'].envra"
- local_action:
module: copy
content: |
{% for host in ansible_play_hosts %}
{{ host }}:
The following packages will be updated -
{{ hostvars[host]['packages']['stdout']|default("None", true) }}
{% endfor -%}
dest: "/tmp/updates.txt"
run_once: yes
tags:
- report
Playbook 1 creates the report, and populates it with debug output. Playbook 2 created the report, but doesn't add debug output. Why? How can I make playbook 2 include output