Q: use of delegated_facts?

Hi,
I am getting confused on the working and purpose of delegated_facts.
If I read the manual correctly:

http://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegated-facts

when you delegate a task to another host than the current managed host from the inventory hosts: list, the ansible facts are gathered from the delegated host but assigned to the current inventory host.
Specifying “delegate_facts: True” would change this that the ansible facts are assigned to the delegated host.

I do not understand what they mean with that facts are assigned to a particular host. When you run a playbook, as it loops over all “hosts:”, facts are gathered and the ansible_* variables get some value valid for that iteration - so without some host qualifier.

The RedHat training manual DO407 (pp.295,296) is not sufficiently explicit about this but appears confused, but from their example I get the impression that it is the other way round.

When I try it myself I see:

  • with just "delegate_to: ", the ansible facts are gathered from the delegated host, which is what I would expect if you run a task on a delegated host;
  • with in addition "delegated_facts: ", the ansible facts are gathered instead from the current inventory host - which means that the name “delegated_facts” is confusing.

So is the documentation wrong?
How is delegated_facts supposed to work?

Here’s the code and output:

<<<<<<<<<<<<<<<<
$ cat inventory
[invhosts]
node1
[delegates]
node2

$ cat testdelegate.yml

Hi,
I am getting confused on the working and purpose of delegated_facts.
If I read the manual correctly:

http://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegated-facts

when you delegate a task to another host than the current managed host from
the inventory hosts: list, the ansible facts are gathered from the
delegated host but assigned to the current inventory host.
Specifying "delegate_facts: True" would change this that the ansible facts
are assigned to the delegated host.

This is correct, and you example does show this.

I do not understand what they mean with that facts are assigned to a
particular host. When you run a playbook, as it loops over all "hosts:",
facts are gathered and the ansible_* variables get some value valid for
that iteration - so without some host qualifier.

I don't now where you have this from, but I think they are referring to Ansible default behavior.
The fist thing Ansible does is to collect from all host, you can see that in the output as "TASK [Gathering Facts]"

This behavior can be changed by the play directive "gather_facts"

The RedHat training manual DO407 (pp.295,296) is not sufficiently explicit
about this but appears confused, but from their example I get the
impression that it is the other way round.

Never seen it.

When I try it myself I see:
- with just "delegate_to: ", the ansible facts are gathered from the
delegated host, which is what I would expect if you run a task on a
delegated host;
- with in addition "delegated_facts: ", the ansible facts are gathered
instead from the current inventory host - which means that the name
"delegated_facts" is confusing.

I think you are being confused because Ansible gather_facts is default true and facts is gathered from both hosts.

So is the documentation wrong?

No, they are correct.

How is delegated_facts supposed to work?

As your example, but I gonna give you a example that might show this more clearly.

Here's the code and output:

<<<<<<<<<<<<<<<<
$ cat inventory
[invhosts]
node1
[delegates]
node2

$ cat testdelegate.yml
---
- name: test delegate functionality
   hosts: invhosts
   tasks:
   - name: setup
     setup:
     delegate_to: "{{ item }}"
# delegate_facts: true
     with_items: "{{ groups['delegates'] }}"
   - name: show
     debug: msg="from fact of {{ inventory_hostname }}, ansible_hostname =
{{ ansible_hostname }}.\n"
# debug: msg="from delegated fact of {{ inventory_hostname }},
ansible_hostname = {{ ansible_hostname }}.\n"
...

$ ansible-playbook testdelegate.yml
PLAY [test delegate functionality]
*******************************************************************************************************************************
TASK [Gathering Facts]
*******************************************************************************************************************************************

Here you see the default task where Ansible gather facts from all host.

Using your inventory try this code, maybe it show the feature more clear since i turn off the default fact gathering.