# Intermittent Hanging of 'Gather Facts' on Local Host in Ansible

**URL:** <https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622>\
**Category:** Get Help\
**Tags:** ansible-core\
**Created:** [September 19, 2024, 11:18am UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622 "2024-09-19T11:18:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jagadeeshkumar\_Ditta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jagadeeshkumar_ditta/32/4805_2.png) [@Jagadeeshkumar\_Ditta](https://forum.ansible.com/u/Jagadeeshkumar_Ditta)\
**Post date:** [September 19, 2024, 11:18am UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/1 "2024-09-19T11:18:31Z")

</div>

We’ve observed intermittent instances where the first step of the Ansible playbook, which gathers facts, hangs for certain VMs. Excerpts of the playbook has been given below and from this, the debug statement that prints all the environment variables passed to the playbook doesn’t get printed ie msg: “{{ env }}”. After killing the hung processes and retrying the operation, it goes through successfully.

Any pointers for debugging this issue would be appreciated, as it is causing serious concerns with the predictability of operations. Thank you inadvance.

- name: Test  
hosts: 127.0.0.1  
tasks:  
- debug:  
msg: “{{ env }}”

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [September 19, 2024, 12:04pm UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/2 "2024-09-19T12:04:00Z")

</div>

Hi. You can disable fact gathering if you don’t need it:

```yaml
---
- name: Test
  hosts: 127.0.0.1
  gather_facts: false
...
```

---

<div class="post-metadata">

**Author:** ![Jagadeeshkumar\_Ditta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jagadeeshkumar_ditta/32/4805_2.png) [@Jagadeeshkumar\_Ditta](https://forum.ansible.com/u/Jagadeeshkumar_Ditta)\
**Post date:** [September 19, 2024, 1:41pm UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/3 "2024-09-19T13:41:29Z")

</div>

Thanks for the quick response. We have disabled the fact gathering now but would like to know what could be the issue.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [September 19, 2024, 2:24pm UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/4 "2024-09-19T14:24:48Z")

</div>

It’s hard to tell what’s wrong based on the information you have provided here.  
The “{{ env }}” variable you are referring to is not an [ansible fact](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#ansible-facts).

---

<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:** [September 19, 2024, 3:15pm UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/5 "2024-09-19T15:15:38Z")

</div>

This is one of the `fun`[DF2014:Fun - Dwarf Fortress Wiki](https://dwarffortresswiki.org/index.php?title=DF2014:Fun&redirect=no) issues that often appear with fact gathering. Most of the time this has to do with an issue with some hardware device, probably a mount or network issue.

To debug fact gathering i would suggest using `gather_subset` to eliminate possible culprits, also set a `gather_timeout` (which is for mount facts). This should narrow down possible culprits.

Ohter options are to strace/dtrace the process on the target machine while it is stuck, see what it is stuck on and try to derive the problem source from there.

---

<div class="post-metadata">

**Author:** ![Jagadeeshkumar\_Ditta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jagadeeshkumar_ditta/32/4805_2.png) [@Jagadeeshkumar\_Ditta](https://forum.ansible.com/u/Jagadeeshkumar_Ditta)\
**Post date:** [September 21, 2024, 11:33am UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/7 "2024-09-21T11:33:20Z")

</div>

Thank you Jorn for taking the time to respond to this. Yes, {{ env }} is not related to Ansible facts, but the issue I was highlighting is that the control never reached that point because it got stuck during the gathering facts step.

---

<div class="post-metadata">

**Author:** ![Jagadeeshkumar\_Ditta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jagadeeshkumar_ditta/32/4805_2.png) [@Jagadeeshkumar\_Ditta](https://forum.ansible.com/u/Jagadeeshkumar_Ditta)\
**Post date:** [September 21, 2024, 11:36am UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/8 "2024-09-21T11:36:20Z")

</div>

This is a great suggestion, Brian. Let me try this out. Thank you so much for the pointers

---

<div class="post-metadata">

**Author:** ![Jagadeeshkumar\_Ditta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jagadeeshkumar_ditta/32/4805_2.png) [@Jagadeeshkumar\_Ditta](https://forum.ansible.com/u/Jagadeeshkumar_Ditta)\
**Post date:** [September 23, 2024, 10:24am UTC](https://forum.ansible.com/t/intermittent-hanging-of-gather-facts-on-local-host-in-ansible/8622/9 "2024-09-23T10:24:16Z")

</div>

Another observation was that I could only see the following statement in `/var/log/messages`, and after that, nothing prints from the gather\_facts task or any other shell commands written in the playbook.

ansible-setup: Invoked with gather\_timeout=10 gather\_subset=[‘all’] filter=\* fact\_path=/etc/ansible/facts.d

Any additional pointers will be much appreciated.
