# variables and delegate\_to

**URL:** <https://forum.ansible.com/t/variables-and-delegate-to/16172>\
**Category:** Ansible Project\
**Created:** [September 10, 2014, 1:24pm UTC](https://forum.ansible.com/t/variables-and-delegate-to/16172 "2014-09-10T13:24:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [September 10, 2014, 1:24pm UTC](https://forum.ansible.com/t/variables-and-delegate-to/16172/1 "2014-09-10T13:24:09Z")

</div>

Hi,

Quick question, I’m defining a group variable to be ‘delegate\_group: test’ or “delegate\_group: live’ depending on the --limit clause used.  
The variable is being properly defined (as can be seen with debug: msg=”"), however when I pass that variable to delegate\_to: “{{ delegate\_group }}” it resolves to the value I filled in but it doesn’t see that this varialbe is actually a group defined in ‘hosts’.  
Is this behavior to be expected? If so, how does one approach a scenario like this?

Thanks,  
Nico.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 10, 2014, 1:27pm UTC](https://forum.ansible.com/t/variables-and-delegate-to/16172/2 "2014-09-10T13:27:20Z")

</div>

delegate\_to does not take a list, but it takes a host name. You can use it with “with\_items” and so on.

I didn’t parse the part about “a group defined in ‘hosts’”

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [September 10, 2014, 1:36pm UTC](https://forum.ansible.com/t/variables-and-delegate-to/16172/3 "2014-09-10T13:36:40Z")

</div>

In my hosts file I have a group defined called ‘live’ for example.

[live]  
[myhost1.example.com](http://myhost1.example.com)  
[myhost2.example.com](http://myhost2.example.com)

I want to delegate\_to: live

Is that possible?

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [September 10, 2014, 8:20pm UTC](https://forum.ansible.com/t/variables-and-delegate-to/16172/4 "2014-09-10T20:20:43Z")

</div>

For those wondering, yes it’s possible as per Michael’s pointer you can use with\_items, so one can do:

delegate\_to: ‘{{ item }}’  
with\_items: groups(‘groupname’)

where groupname can also be a (custom) fact or variable.
