# delegated facts quit working

**URL:** <https://forum.ansible.com/t/delegated-facts-quit-working/37191>\
**Category:** Ansible Project\
**Created:** [October 7, 2022, 8:53pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191 "2022-10-07T20:53:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 7, 2022, 8:53pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191/1 "2022-10-07T20:53:26Z")

</div>

Bit of a mystery. We’ve been using the following task for quite some time. Note that it uses a technique documented in [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_delegation.html#delegating-facts](https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#delegating-facts)

```auto
    - name: gather facts on our delegated download host
      ansible.builtin.setup:
      delegate_to: "{{ tcDelegate }}"
      delegate_facts: True
      when: hostvars[tcDelegate]['ansible_default_ipv4']['address'] is not defined

```

For reasons we’ve yet to determine, some time fairly recently, it quit populating `hostvars[tcDelegate]`. It’s still gathering the facts. It’s just that they don’t seem to be stored anywhere. After this task succeeds, tcDelegate is not one of the keys to `hostvars`.

Is this a known thing? We’re running `ansible [core 2.12.6]`, `python version = 3.8.12`, `jinja version = 3.1.2` on `Red Hat 8.5.0-3`.

​

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 7, 2022, 9:21pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191/2 "2022-10-07T21:21:39Z")

</div>

It works if the host is defined in inventory, it should work even if  
not, checking why this happens.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 7, 2022, 9:35pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191/3 "2022-10-07T21:35:04Z")

</div>

I cannot seem to make it work on any version since 2.9 w/o the host  
being in inventory. Do you have a specific version in which it works?

I cannot make it fail if the host we delegate to is in inventory.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 7, 2022, 9:35pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191/4 "2022-10-07T21:35:12Z")

</div>

Thanks. The delegated to host is definitely in the same inventory. And it’s worked fine for I guess a couple of years. Very strange.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 8, 2022, 5:54pm UTC](https://forum.ansible.com/t/delegated-facts-quit-working/37191/5 "2022-10-08T17:54:48Z")

</div>

Your comments about the inventory were crucial.

We have 148 hosts in our inventory. I was throwing debug tasks all over the place dumping out hostvars.keys(), and I was always getting 37 hosts, and it never included the delegate. It was an strange but consistent hodge-podge of seemingly unrelated hosts.

4 × 37 = 148

We are running under AWX, and someone (with whom I’ll have a discussion on Monday) set Job Slicing=4 in the template for this project in an attempt to reduce resource requirements for this job. Job Slicing seems like a great way to split up a large inventory into a bunch of smaller ones so individual jobs aren’t so huge that you run out of resources. But it only works if all your hosts’ jobs are truly independent from all other hosts in your inventory. In our case, our delegate ended up in a separate slice from the hosts we were running on, so it’s effectively in a different inventory when Job Slicing\>1. This is why when we gathered facts (ansible.builtin.setup) for that host they never showed up in hostvars. Dropping it back to 1 restored sanity.

It may be possible to rework some things so that individual hosts are truly independent throughout the job, and we can crank up Job Slicing again.

Thanks for your time and efforts.
