I was trying to loop through all my hosts and if a certain package (xauth in this case) was present it would create a list and email that list with this information:
If package was found:
HOSTNAME - PACKAGE_NAME:VERSION
I thought this would work but it does not.
- name: SET FACT FOR PACKAGE PRESENCE
set_fact:
package_presence: "{{ ansible_facts.packages['xauth'] }}"
ignore_errors: True
#
#
- name: LIST HOSTNAME, PACKAGE NAME AND VERSION IF PRESENT
set_fact:
machine_info:
"{% for host in ansible_play_batch %}{% if package_presence is defined %}{{ hostvars[host]['ansible_hostname'] }} - {{ hostvars[host]['ansible_facts']['packages']['xauth'][0]['name'] }}:{{ hostvars[host]['ansible_facts']['packages']['xauth'][0]['version'] }}<br>{% else %}XAUTH Not Found on {{ hostvars[host] }}<br>{% endif
%}{% endfor %}"
run_once: yes
ignore_errors: True
This is the error I receive:
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'xauth'\n\nThe error appears to be in '/var/lib/awx/projects/roles/Package_Information/tasks/main.yml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#\n- name: LIST HOSTNAME, PACKAGE NAME AND VERSION IF PRESENT\n ^ here\n",