Hi,
It seems setup module with delegate_to doesn't work as intended in Ansible prior to 2.0. It actually updates facts of self (hostvars[inventory_hostname]) with facts of delegated host. Ansible 2.0 successfully updates delegated host's hostvars. Confirmed with the following playbook:
---
- hosts: localhost
gather_facts: no
tasks:
- debug:
var: hostvars.localhost.ansible_hostname | default(false)
- setup:
delegate_to: remotehost
- debug:
var: hostvars.localhost.ansible_hostname | default(false)
- debug:
var: hostvars.remotehost.ansible_hostname | default(false)
Ansible 1.9.3: Note that hostvars.localhost.ansible_hostname returns "remotehost" after setup. Other fact variables are also updated with remotehost's. hostvars.remotehost gets no update.
$ ansible-playbook -i hosts playbook.yml
PLAY [localhost] **************************************************************
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"var": {
"hostvars.localhost.ansible_hostname | default(false)": "False"
}
}
TASK: [setup ] ****************************************************************
ok: [localhost -> remotehost]
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"var": {
"hostvars.localhost.ansible_hostname | default(false)": "remotehost"
}
}
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"var": {
"hostvars.remotehost.ansible_hostname | default(false)": "False"
}
}
PLAY RECAP ********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0
Ansible 2.0.0: hostvars.localhost remains undefined after setup. hostvars.remotehost is correctly updated with remotehost's facts.
$ ansible-playbook -i hosts playbook.yml
PLAY ***************************************************************************
TASK [debug var=hostvars.localhost.ansible_hostname | default(false)] **********
ok: [localhost] => {
"changed": false,
"hostvars.localhost.ansible_hostname | default(false)": false
}
TASK [setup] *******************************************************************
ok: [localhost]
TASK [debug var=hostvars.localhost.ansible_hostname | default(false)] **********
ok: [localhost] => {
"changed": false,
"hostvars.localhost.ansible_hostname | default(false)": false
}
TASK [debug var=hostvars.remotehost.ansible_hostname | default(false)] *********
ok: [localhost] => {
"changed": false,
"hostvars.remotehost.ansible_hostname | default(false)": "remotehost"
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0