Hello Ansible experts, I am having a ‘hostgroup’ with a ‘host_var’ associated with each host of the ‘hostgroup’. Play 1 which targets the ‘hostgroup’, will create files on the target servers using the associated ‘host_var’ and get the files back to ansible control machine and zip/archive the files. Play 2 which runs local to ansible control machine, needs to check for the files created, file name is ‘targethostname.txt’, and then create an email template with a table containing successful hosts and their associated ‘host_var’ using jinja2 and then send an email with a table of list of targethostnames and their associated host_vars.
I have completed the code for generating and copying the files to ansible control machine, zip, create a html template and send an email. I am struck at referencing/generating the html template file with a table consisting of the successful ‘targethostnames’ and their associated ‘host_var’ in the html template. Can anyone please help me with an approach to achieve the list of successful targethostnames and their host_vars in a jinja2 template. Thanks in advance.
`
{% for host in ansible_play_batch %}
{% endfor %}HOSTNAME / FQDN | HOST VAR |
---|---|
{{ inventory_hostname }} | {{ host_var }} |
`
The above doesn’t seem to work. (Also, previously I had both the tasks - now Play 1 and Play 2 - in a single play and had to use the ansible_play_batch, as above, but, neither that didn’t work.)