Targeting hosts in a group in order with Ansible

Viewed 201

In Patterns: targeting hosts and groups — Ansible Documentation it is suggested that it is possible when using Ansible to target hosts in a group in order. For example the documentation uses a group webservers

[webservers]
cobweb
webbing
weber

The documentation then suggests that using webservers[0] would to target cobweb. In my environment I have two nodes in a group and targeting the first node using [0] will return the second and not the first node in the group.

Ansible runs in AWX and the inventory project is based on Git source. AWX also lists the group in correct order in the web interface but when I output the group it is in reverse order.

- debug:
    msg: "hosts: {{ groups['my_group'] }}"

Is this is a known issue? The results I am getting I think suggest that the order is randomized. So the documentation is incorrect or there is a bug in Ansible or AWX.

I am using Ansible 2.9.17 with AWX 17.0.1.

The way the groups vars is sorted is IMHO independent of order strategy. So for example when I have a play as shown below I can tell Ansible to use inventory order.

  hosts: my_group
  order: inventory
  roles: ... 

This is has no relation to order of list groups['my_group'] as far I can tell.

0 Answers
Related