0

How can I reference a tower inventory group from the playbook? My playbook is calling specific roles, each role will call on a different inventory group from tower.

So far what I have tried is:

host: "{{ inventory_hostname in groups['ios'] }}"

or

host: "ios"

or

host: ios

Is it just my syntax there on the templating? I can't find any reference to this when using a tower inventory group.

I get some type of error stating could not be found, or attempting to acctually connect to "ios"

"failed to connect to ios:22"
hiddenicon
  • 551
  • 2
  • 11
  • 23

3 Answers3

0

You should use hosts: instead of host: if you want to reference a group.

Kourkis
  • 57
  • 3
  • I split out my playbook to separate the groups, so I'll put it back to original and try this. Is there documentation for the hosts vs host? – hiddenicon Apr 27 '17 at 14:07
  • I would recommend reading this: http://docs.ansible.com/ansible/playbooks_intro.html#hosts-and-users – Kourkis May 09 '17 at 20:16
0

From Ansible Tower support:

Each job template can see only one top-level inventory. It is possible, though, to create potentially overlapping groups and sub-groups within a single inventory. For most applications, the single inventory can be organized to provide necessary specificity. In cases where an particular inventory grouping must be referenced in multiple job templates, it is necessary to either use the same top-level inventory in both cases, or to duplicate the inventory group to both inventories.

So you can't reference other groups in hosts, each job template only sees the inventory it was provided but you can either use Workflow to change inventories or create overlapping groups.

kamranicus
  • 4,207
  • 2
  • 39
  • 57
0

Try starting with: hosts: "{{ ansible_play_batch }}"

This "magic variable" gives you the list of [active, reachable] Hosts that were passed in from Tower.

I came to this because hosts: is a required field in the playbook, and I didn't want to hard-code over the top of the Tower Inventory selection.

Basavaraj Metri
  • 836
  • 1
  • 14
  • 27