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 --- - 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] ******************************************************************************************************************************************* ok: [node1] TASK [setup] ***************************************************************************************************************************************************** ok: [node1 -> node2] => (item=node2) TASK [show] ****************************************************************************************************************************************************** ok: [node1] => { "changed": false, "msg": "from fact of node1, ansible_hostname = node2.\n" } PLAY RECAP ******************************************************************************************************************************************************* node1 : ok=3 changed=0 unreachable=0 failed=0 #<!-- So with delegate_to, the facts are gotten from the delagate_to host instead of from the current managed inventory_host #--> $ vim testdelegate.yml #<!-- uncomment delegate_facts --> $ ansible-playbook testdelegate.yml PLAY [test delegate functionality] ******************************************************************************************************************************* TASK [Gathering Facts] ******************************************************************************************************************************************* ok: [node1] TASK [setup] ***************************************************************************************************************************************************** ok: [node1 -> node2] => (item=node2) TASK [show] ****************************************************************************************************************************************************** ok: [node1] => { "changed": false, "msg": "from delegated fact of node1, ansible_hostname = node1.\n" } PLAY RECAP ******************************************************************************************************************************************************* node1 : ok=3 changed=0 unreachable=0 failed=0 >>>>>>>>>>>>>>>> #<!-- So with delegate_facts, the facts are gotten from the current managed inventory_host instead of from the delegate_to host. #--> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/40280402-feb7-4bf6-9835-3f53be52aa61%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
