delegated facts quit working

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

    - 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.

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

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.

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.

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.