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
On Thursday, September 3, 2015 at 4:36:31 PM UTC+9, Roman Belyakovsky wrote:
> Hello!
>
> I have an issue: delegate_to works incorrectly with with_items. I cannot
> collect missing facts. I've opened an issue
> <https://github.com/ansible/ansible/issues/12222> but it was already
> closed. Is there anything wrong with my playbook?
>
> Thank you,
> Yours Faithfully,
> Roman Belyakovsky
>
Regards,
--
YAEGASHI Takeshi <[email protected]>
--
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/129af34a-6381-4407-b902-e6e401a3b1da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.