How can I obtain all members of the group 'mygroup' when the name of the group is taken from a variable?
Косвенная адресация недоступна в Ansible.
Можно сопоставить , selectattr с помощью переменной и map со списком хостов в группе. С инвентарем ниже
$ cat hosts
localhost
[mygroup]
test_01
test_02
test_03
игра ниже
- hosts: localhost
tasks:
- set_fact:
variable: mygroup
- set_fact:
my_hosts: "{{ groups|
dict2items|
selectattr('key', 'match', variable)|
map(attribute='value')|
list|
flatten }}"
- debug:
var: my_hosts
дает
"my_hosts": [
"test_01",
"test_02",
"test_03"
]