But ansible throw me an error:
The conditional check ‘ansible_facts[‘ansible_os_family’] == "RedHat"’ failed. The error was: error while evaluating conditional (ansible_facts[‘ansible_os_family’] == "RedHat"): ‘dict object’ has no attribute ‘ansible_os_family’
And only when i changed my task to:
when: ansible_facts[‘os_family’] == ‘RedHat’ # without “ansible_” for key dict
It start to work. Why is it so, I am saw in output key “ansible_os_family”, not “os_family”? Should I delete all leading “ansible_” from output setup module? Is it documented?
P.S. also it works even with just:
when: ansible_os_family == ‘RedHat’ condition.
To determine how to reference variable which store OS family type i ran:
ansible node1 -m setup
Which throw a lot of output but there was:
192.168.24.24 | SUCCESS => {
"ansible_facts": {
...,
"ansible_os_family": "RedHat",
...
},
"changed": false
}
Based on it i reference in task to family vars as follows:
when: ansible_facts['ansible_os_family'] == 'RedHat'
But ansible throw me an error:
The conditional check 'ansible_facts['ansible_os_family'] ==
\"RedHat\"' failed. The error was: error while evaluating conditional
(ansible_facts['ansible_os_family'] == \"RedHat\"): *'dict object' has
no attribute 'ansible_os_family'*
*
*
And only when i changed my task to:
when: ansible_facts['os_family'] == 'RedHat' # without "ansible_" for
key dict
It start to work. Why is it so, I am saw in output key
"*ansible_os_family*", not "*os_family*"? Should I delete all leading
"ansible_" from output setup module? Is it documented?
There is an effort to move gathered facts into their own namespace under ansible_facts, dropping the ansible_ prefix on each fact.
P.S. also it works even with just:
when: ansible_os_family == 'RedHat' condition.
This is the "old" way of accessing the fact, though I'd expect it to remain supported for a long time.