On 12/08/2021 17:38, [email protected] wrote:
I'm trying to create a report when we do our updates via yum (rhel 7) and dnf 
(rhel 8).  I register the output in variables called yum_rhel7 and yum _rhel8.  
Here's my j2 file:

Yum/DNF Update Report

{{ now(false, '%m/%d/%Y %I:%M:%S') }}

---
{% for i in play_hosts | sort %}
{% if {{ hostvars[i]['ansible_distribution_major_version'] == '7' }} %}
{% if {{ hostvars[i]['yum_rhel7']['skipped'] is not defined }} %}
   Host: {{ i }}
   Yum Result: {{ hostvars[i]['yum_rhel7']['results'] }}
{% endif %}
{% endif %}
---
{% endfor %}

No curly braces in conditions, e.g. use

{% if hostvars[i]['ansible_distribution_major_version'] == '7' %}

Also

{% if 'skipped' not in hostvars[i]['yum_rhel7'] %}

is probably more correct.

Regards
       Racke



I'm getting the following error when I run the playbook:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: template 
error while templating string: expected token ':', got '}'. String: Yum/DNF Update Report\n\n{{ now(false, 
'%m/%d/%Y %I:%M:%S') }}\n\n---\n{% for i in play_hosts | sort %}\n{% if {{ 
hostvars[i]['ansible_distribution_major_version'] == '7' }} %}\n{% if {{ hostvars[i]['yum_rhel7']['skipped'] is 
not defined }} %}\n  Host: {{ i }}\n  Yum Result: {{ hostvars[i]['yum_rhel7']['results'] }}\n{% endif %}\n{% 
endif %}\n---\n{% endfor %}\n\n"}

Any ideas on what I'm doing wrong?
Thanks,
Harry

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 
[email protected] 
<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/be4a68ec-5c3f-45d3-a8e0-82607cdfdac5n%40googlegroups.com
 
<https://groups.google.com/d/msgid/ansible-project/be4a68ec-5c3f-45d3-a8e0-82607cdfdac5n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/745ec456-560e-8649-fe77-4e8008a4d50b%40linuxia.de.

Reply via email to