ansible_facts['ansible_os_family'] vs. ansible_facts['os_family']

713 views
Skip to first unread message

Михаил Политаев

unread,
Jul 28, 2019, 12:18:38 PM7/28/19
to Ansible Project
Hello community!

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?



P.S. also it works even with just:
when: ansible_os_family == 'RedHat' condition.

James Cassell

unread,
Jul 28, 2019, 4:16:54 PM7/28/19
to Ansible List

On Sun, Jul 28, 2019, at 12:18 PM, Михаил Политаев wrote:
> Hello community!
>
> 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.

V/r,
James Cassell

Михаил Политаев

unread,
Jul 28, 2019, 4:33:12 PM7/28/19
to ansible...@googlegroups.com

Thanks for answer James!


Also want to know dropping leading "ansible_" are not documented and i am asking not on vain or i just read without attention?


вс, 28 июл. 2019 г., 22:16 James Cassell <fedora...@cyberpear.com>:
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/vvrGJjjGfuI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f5254b17-6f67-4e4a-99d2-4d74195a44c2%40www.fastmail.com.
Reply all
Reply to author
Forward
0 new messages