I have a diagnostic task that dumps the Ansible dictionaries at the end of a run. However if the hosts fail the Playbook stops and my task doesn’t get executed. But of course that’s when it’s most important. How can I arrange that this task always runs after everything else?
For what it’s worth, here’s my dump_vars code. The real goal is to have a data dump at the end of each Playbook. Another means to this end would also be a valuable solution.
… Other Playbook code …
Last Play
-
hosts: localhost
gather_facts: no
tasks: -
name: dump all vars
local_action: template src=dump_vars.j2 dest=./dump_vars.out
tags: [testing1]
ignore_errors: yes
changed_when: False
cat dump_vars.j2
{
“aaa_export_info1”: “Export of all Ansible 1.x Dicts as a single JSON dict”,
“aaa_export_info2”: “This file combines the dicts into a single JSON record”,
“aaa_export_info3”: “Note that indentation is a bit off”,
“vars”: {{ vars | remove_sensitive_data | to_nice_json }},
“environment”: {{ environment | remove_sensitive_data | to_nice_json }},
“group_names”: {{ group_names | remove_sensitive_data | to_nice_json }},
“groups”: {{ groups | remove_sensitive_data | to_nice_json }},
“hostvars”: {{ hostvars | remove_sensitive_data | to_nice_json }}
}