Retrieve host list from group name or pass group name to delegate_to in AWX

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

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