# Ansible\_os\_family not defined

**URL:** <https://forum.ansible.com/t/ansible-os-family-not-defined/38907>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [December 5, 2024, 6:54am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907 "2024-12-05T06:54:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibhor\_agarwalin](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@vibhor\_agarwalin](https://forum.ansible.com/u/vibhor_agarwalin)\
**Post date:** [December 5, 2024, 6:54am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/1 "2024-12-05T06:54:18Z")

</div>

Hello Folks,

My AWX jobs are failing with “ansible\_os\_family” not defined for a particular host.  
Have the gather\_facts = true.

Triaged further via cli tells only this particular host doesn’t have it defined. All rest (1000+) have it set.

All hosts:  
ansible -i inventory -l host1 all -m setup | grep ansible\_os\_family  
“ansible\_os\_family”: “Debian”,

Problematic host:  
ansible -i inventory -l host2 all -m setup | grep ansible\_os\_family  
\<\>

Host2 is U22.  
Kindly share details how ansible captures this variable & how to troubleshoot it further?

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [December 5, 2024, 3:06pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/2 "2024-12-05T15:06:40Z")

</div>

Can you insert this task before the task that uses `ansible_os_family`:

```auto
- name: Debug ansible_facts
  debug:
    msg: "{{ ansible_facts }}"

```

This should show you what was captured by Ansible from the host2 during the fact gathering phase.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [December 5, 2024, 5:22pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/3 "2024-12-05T17:22:40Z")

</div>

Also check your configuration,[INJECT\_FACTS\_AS\_VARS](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inject-facts-as-vars) will enable/prevent top level variables from being created. Note that `ansible_facts['os_family']` would be present either way if facts were gathered or cached.

---

<div class="post-metadata">

**Author:** ![vibhor\_agarwalin](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@vibhor\_agarwalin](https://forum.ansible.com/u/vibhor_agarwalin)\
**Post date:** [December 6, 2024, 7:59am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/4 "2024-12-06T07:59:43Z")

</div>

Thanks for the inputs folks,  
Believe debugging this outside AWX directly via cli will be easier as it’s easily reproducible in cli.

Kindly refer below output.  
Believe problem lies in how ansible populates these values. That underlying data is missing on host.

Working host  
ansible -i inventory -l host1 all -m setup | grep ansible\_os\_family  
“ansible\_os\_family”: “Debian”,  
ansible -i inventory -l host1 all -m setup | grep ansible\_facts[‘os\_family’]  
\<\>

Problematic host  
ansible -i inventory -l host2 all -m setup | grep ansible\_os\_family  
\<\>  
ansible -i inventory -l host2 all -m setup | grep ansible\_facts[‘os\_family’]  
\<\>

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [December 6, 2024, 4:22pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/5 "2024-12-06T16:22:01Z")

</div>

FYI, the output of the setup module will have the `ansilbe_` prefix on facts, it is when used in a playbook that the prefix is removed and only added back in the case of ‘injection’ being enabled. When using ‘adhoc’ you do not get any of this processing.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [December 6, 2024, 4:37pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/6 "2024-12-06T16:37:29Z")

</div>

I would try `ansible -i inventory -l host2 all -m setup | grep os_family` since this will catch the fact if it exists with or without the `ansible_` prefix. I’m also curious if `ansible -i inventory -l host2 all -m setup | grep distribution` returns anything.

If only a single host among _thousands_ is failing to report these facts (prefix or not), then I would think that perhaps something is wrong with that host’s `/etc/os-release` file. Modifications to this file (or missing it entirely) can cause Ansible to misclassify or fail to gather OS related facts altogether.

---

<div class="post-metadata">

**Author:** ![vibhor\_agarwalin](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@vibhor\_agarwalin](https://forum.ansible.com/u/vibhor_agarwalin)\
**Post date:** [December 9, 2024, 5:51am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/7 "2024-12-09T05:51:43Z")

</div>

Output is pretty much same with modified grep’s.

Working host:  
ansible -i inventory -l host1 all -m setup | grep os\_family  
“ansible\_os\_family”: “Debian”,  
ansible -i inventory -l host1 all -m setup | grep distribution  
“ansible\_distribution”: “Ubuntu”,  
“ansible\_distribution\_file\_parsed”: true,  
“ansible\_distribution\_file\_path”: “/etc/os-release”,  
“ansible\_distribution\_file\_variety”: “Debian”,  
“ansible\_distribution\_major\_version”: “20”,  
“ansible\_distribution\_release”: “focal”,  
“ansible\_distribution\_version”: “20.04”,

Problematic host:  
ansible -i inventory -l host2 all -m setup | grep os\_family  
\<\>  
ansible -i inventory -l host2 all -m setup | grep distribution  
\<\>

> If only a single host among _thousands_ is failing to report these facts (prefix or not), then I would think that perhaps something is wrong with that host’s `/etc/os-release` file.

Yes, only 1 host has problem.  
/etc/os-release is identical to other hosts.

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [December 10, 2024, 1:37pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/8 "2024-12-10T13:37:34Z")

</div>

This is the function that defines ansible\_os\_family [ansible/lib/ansible/module\_utils/facts/system/distribution.py at v2.18.1 · ansible/ansible · GitHub](https://github.com/ansible/ansible/blob/v2.18.1/lib/ansible/module_utils/facts/system/distribution.py#L545). What’s the value of `platform.system()` (using the same Python interpreter as the `setup` module) on the problematic host?

`ansible -i inventory host2 -m command -a '{{ ansible_python_interpreter }} -c "import platform; print(platform.system())"'`

If you don’t have `ansible_python_interpreter` defined in inventory, you can check the discovered interpreter to use in that command:

`ansible -i inventory host2 -m setup -a 'gather_subset="!all,!min,python"'`

---

<div class="post-metadata">

**Author:** ![vibhor\_agarwalin](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@vibhor\_agarwalin](https://forum.ansible.com/u/vibhor_agarwalin)\
**Post date:** [December 11, 2024, 6:29am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/9 "2024-12-11T06:29:52Z")

</div>

Getting same & good output for both systems.

ansible -i inventory host1 -m command -a ‘/usr/bin/python -c “import platform; print(platform.system())”’  
host1 | CHANGED | rc=0 \>\>  
Linux

ansible -i inventory host2 -m command -a ‘/usr/bin/python -c “import platform; print(platform.system())”’  
host2 | CHANGED | rc=0 \>\>  
Linux

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [December 11, 2024, 8:06pm UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/10 "2024-12-11T20:06:02Z")

</div>

If collecting any of the fact subsets (including `distribution`) fails with an Exception, that subset of facts would just be an empty dictionary due to how it’s handled here [ansible/lib/ansible/module\_utils/facts/ansible\_collector.py at v2.18.1 · ansible/ansible · GitHub](https://github.com/ansible/ansible/blob/v2.18.1/lib/ansible/module_utils/facts/ansible_collector.py#L90).

It might be easier to debug with `-vvv` than tracing the code (assuming you’re using the ssh connection plugin which includes the detail at that verbosity level): `ansible -i inventory host2 -m setup -a 'gather_subset="!min,!all,distribution"' -vvv | grep '.*{"ansible_facts":.*"'`

The gather\_subset option limits the running code/output, and the grep matches the JSON returned by the setup module in -vvv since otherwise there’s a lot to sift through.

I’m just emulating the behavior by raising an arbitrary exception in the distribution facts logic, but the output could look similar to:

```auto
<host2> (0, b'TypeError("emulate issue collecting distribution facts")\r\n\r\n{"ansible_facts": {"gather_subset": ["!min", "!all", "distribution"], "module_setup": true}, "invocation": {"module_args": {"gather_subset": ["!min", "!all", "distribution"], "gather_timeout": 10, "filter": [], "fact_path": "/etc/ansible/facts.d"}}}\r\n', ...

```

---

<div class="post-metadata">

**Author:** ![vibhor\_agarwalin](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@vibhor\_agarwalin](https://forum.ansible.com/u/vibhor_agarwalin)\
**Post date:** [December 12, 2024, 4:17am UTC](https://forum.ansible.com/t/ansible-os-family-not-defined/38907/11 "2024-12-12T04:17:24Z")

</div>

Bingo, was able to find the root cause.

Can you help me understand how does the ssh verbose option of -vvv fit here?  
And how do I find which ansible variable belong to which `gather_subset` group?

Here we go:

ansible -i inventory host2 -m setup -a ‘gather\_subset=“!min,!all,distribution”’ -vvv | grep ‘._{“ansible\_facts”:._"’  
 (0, b’CalledProcessError(1, ('lsb\_release', '-a'))\r\n\r\n{“ansible\_facts”: {“gather\_subset”: [“!min”, “!all”, “distribution”], “module\_setup”: true}, “invocation”: {“module\_args”: {“gather\_subset”: [“!min”, “!all”, “distribution”], “gather\_timeout”: 10, “filter”: “\*”, “fact\_path”: “/etc/ansible/facts.d”}}}\r\n’, b’')

Above told lsb\_release process error. When i ran the same on host, it did fail.  
Fixed it & we are back to normal 😀.
