I'm attempting to get Ansible to check CentOS and RedHat OS versions. If the version is less than 7.9 then it will list: Hostnames - OS Version in an email. However, Ansible does not appear to be evaluating this properly because I receive an email list of machines with version 7.9.:
- name: COLLECT INFORMATION ON ALL MACHINES
set_fact:
machine_info:
"{% for host in ansible_play_batch %}{% if ansible_facts.distribution_version | float < 7.9 %}{{ hostvars[host]['ansible_hostname'] }} - {{ hostvars[host]['ansible_distribution'] }} {{ hostvars[host]['ansible_distribution_version'] }}<br>{% endif %}{% endfor %}"
run_once: yes
ignore_errors: True
#
#
- name: EMAIL HOSTNAME, OS AND VERSION
mail:
to: "{{ email_to[app_owner] }}"
from: Ansible Tower <REDACTED>
subject: "Ansible Notification: OS Information [{{ awx_inventory_name }}]"
subtype: html
body: '<!DOCTYPE html>
<html>
<body>
<h3>{{ machine_info | upper }}</h3><br><br>
</body>
</html>'
host: REDACTED
run_once: true
become: false
delegate_to: localhost