Ansible Not Properly Evaluating Filter Using Less Than For OS Version

37 views
Skip to first unread message

m.hay...@apogee-innovations.com

unread,
Jun 9, 2021, 4:58:41 PM6/9/21
to AWX Project
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.:

VMGUEST03 - REDHAT 7.8
VMGUEST01 - REDHAT 7.9
VMGUEST02 - REDHAT 7.8


Does anyone know how I can correct this?

Here's my Playbook:

- 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
Reply all
Reply to author
Forward
0 new messages