Team: I am trying to fail a task when two conditions are not met on a node. ansible_facts['distribution_version']
and ansible_facts['distribution']
.
I am passing in two nodes. one node is 20.x
ubuntu and other is 18.x
.
vars/main.yml
os_distribution: "Ubuntu"
os_version: "20.04"
task is below
- name: "Check Base OS Version maps to expected distribution version {{ os_version }}"
fail:
msg: "Task failed as unexpected OS version found: {{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_version'] }} on {{ inventory_hostname }}"
when:
- ansible_facts['distribution_version'] is version(os_version, '<')
- os_distribution != ansible_facts['distribution']
result
TASK [node-validation : Check Base OS Version maps to expected distribution version 20.04] ***
Tuesday 23 November 2021 20:11:32 +0000 (0:00:17.570) 0:00:17.690 ******
skipping: [node1]
skipping: [node2]
expected output: observe 18.x below not sure what am i missing to get that.
fatal: [node2]: FAILED! => {"changed": false, "msg": "Task failed as unexpected OS version found: Ubuntu 18.04 on node2"}
When I remove - os_distribution != ansible_facts['distribution']
then I get expected result as below but I want to satisfy two conditions not just one.
[fatal: [node2]: FAILED! => {"changed": false, "msg": "Task failed as unexpected OS version found: Ubuntu 18.04 on node2 }}"}
reference to ansible_facts
FACTS for 20.x
10:17:59 [0;32m "distribution": "Ubuntu",[0m
10:17:59 [0;32m "distribution_file_parsed": true,[0m
10:17:59 [0;32m "distribution_file_path": "/etc/os-release",[0m
10:17:59 [0;32m "distribution_file_variety": "Debian",[0m
10:17:59 [0;32m "distribution_major_version": "18",[0m
10:17:59 [0;32m "distribution_release": "bionic",[0m
10:17:59 [0;32m "distribution_version": "18.04",[0m
FACTS for 20.x
10:23:43 [0;32m "distribution": "Ubuntu",[0m
10:23:43 [0;32m "distribution_file_parsed": true,[0m
10:23:43 [0;32m "distribution_file_path": "/etc/os-release",[0m
10:23:43 [0;32m "distribution_file_variety": "Debian",[0m
10:23:43 [0;32m "distribution_major_version": "20",[0m
10:23:43 [0;32m "distribution_release": "focal",[0m
10:23:43 [0;32m "distribution_version": "20.04",[0m