# delegate\_to and delegate\_facts not working as expected

**URL:** <https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370>\
**Category:** Ansible Project\
**Created:** [January 3, 2017, 7:40pm UTC](https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370 "2017-01-03T19:40:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_Watson](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@Neil\_Watson](https://forum.ansible.com/u/Neil_Watson)\
**Post date:** [January 3, 2017, 7:40pm UTC](https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370/1 "2017-01-03T19:40:11Z")

</div>

Consider these tasks:

`

- name: Gather facts about new VM  
delegate\_to: “{{ new\_vm }}”  
delegate\_facts: true  
setup:  
register: host\_info

- name: install prereqs  
delegate\_to: “{{ new\_vm }}”  
package:  
name: “{{ item }}”  
state: present  
with\_items:

- at  
`

This results in:

TASK [provision\_vm\_and\_set\_ip : Gather facts about new VM] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [jenkins2 → 10.120.8.220]

TASK [provision\_vm\_and\_set\_ip : install prereqs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [jenkins2 → 10.120.8.220] (item=[u’at’]) =\> {“failed”: true, “item”: [“at”], “msg”: “Could not detect which package manager to use. Try gathering facts or setting the "use" option.”}

Why does the package task fail when the setup task appeared to pass?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 3, 2017, 7:53pm UTC](https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370/2 "2017-01-03T19:53:52Z")

</div>

Because you are consuming the facts of the inventory\_hostname, not delegate\_to host (this only overrides the connection variables).

- hosts: new\_vm  
tasks:
- package:

will work.

---

<div class="post-metadata">

**Author:** ![Neil\_Watson](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@Neil\_Watson](https://forum.ansible.com/u/Neil_Watson)\
**Post date:** [January 3, 2017, 8:09pm UTC](https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370/3 "2017-01-03T20:09:54Z")

</div>

Can you set a new host in a role?

roles/vm/tasks/main.yml

- name task 1

- name task 2

-host

tasks:

- name: task on delegate host

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 3, 2017, 8:52pm UTC](https://forum.ansible.com/t/delegate-to-and-delegate-facts-not-working-as-expected/23370/4 "2017-01-03T20:52:09Z")

</div>

no, its a new play
