How to get all hosts from inventory that are in a specified group into a variable??

Hi,

I am (still) new to working with Ansible…

In the inventory in our tower environment, we have groups configured.

I am trying to modify an existing playbook (and template file) to set a new property, “cache.memberlist”, with a value of all the hostnames in a specific group named, “SVC”.

I tested a small playbook:

  • hosts: all
    gather_facts: true
    tasks:
  • set_fact:
    host_list: “{{ groups[‘SVC’] }}”
  • debug:
    msg: “{{host_list}}”

That does look like it is finding the hostnames, but (a) it is doing that for every host in the inventory and (b) it looks like, for every host, it is trying to connect to that host.

Is there some way that the playbook can just find (and return) the hostnames that are in the SVC group and return that?

Thanks,
Jim

Hi,

I think that I figured my question out… it was a “momentary fog” on my part :(… I have been using mostly ansible-playbook, and hardly ever used tower, but I just realized that I needed to put the specific hosts in the “limit” on the template page in Tower. Then, it only runs the playbook against those specific hosts.

Sorry about that!

Jim