# Retrieve host list from group name or pass group name to delegate\_to in AWX

**URL:** <https://forum.ansible.com/t/retrieve-host-list-from-group-name-or-pass-group-name-to-delegate-to-in-awx/38068>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [June 6, 2023, 4:24pm UTC](https://forum.ansible.com/t/retrieve-host-list-from-group-name-or-pass-group-name-to-delegate-to-in-awx/38068 "2023-06-06T16:24:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hemanth\_Kumar\_Simhad](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Hemanth\_Kumar\_Simhad](https://forum.ansible.com/u/Hemanth_Kumar_Simhad)\
**Post date:** [June 6, 2023, 4:24pm UTC](https://forum.ansible.com/t/retrieve-host-list-from-group-name-or-pass-group-name-to-delegate-to-in-awx/38068/1 "2023-06-06T16:24:29Z")

</div>

Hi Team,

My use case is to run the task on group of hosts as a pre-task but I am having trouble passing group\_name to delegate\_to in the playbook as it expects only a string not a list.

Then I tried to use the loop option but it is unable to retrieve the list of host name from the group name in AWX. it passes the group name as literal to that loop. Could someone help if you tried this approach already or any alternative suggestion.

sample task:

- name: Generate ip addresses from the group varaiable.  
delegate\_to: “{{ item }}”  
loop: “{{ selected\_groups }}”  
delegate\_facts: true

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [June 9, 2023, 5:14pm UTC](https://forum.ansible.com/t/retrieve-host-list-from-group-name-or-pass-group-name-to-delegate-to-in-awx/38068/2 "2023-06-09T17:14:19Z")

</div>

is selected\_group just the name of the group itself? if so we want this to be a list of hosts IN that group

you might try replacing selected\_groups with groups[‘group\_name’], or something similar to access the hosts in the group

you also probably want to use the “run\_once: true” on this task since you are looping over hosts, otherwise this task may run multiple times per host

AWX Team
