How To Use Ansible Module Wait_for Together With Loop?
Solution 1:
After consulting with colleagues it turned out that the list (of servers) wasn't defined correctly in inventory, just a classical syntax error. Please see Ansible, how to define a list in host inventory?.
To get it working it is necessary to define in inventory file the variable as
SCOM_MGMT_SRV_PROD="['server1','server2','server3','server4']"
instead of an just comma separated list of strings and use for loop
loop: "{{ SCOM_MGMT_SRV_PROD }}"
By doing this I've realized that actually the debug message wasn't iterating over the list either. Now it is working properly
TASK [debug] ************************************************************************************************************************
ok: [host] => (item=server1) => {
"msg": "server1"
}
ok: [host] => (item=server2) => {
"msg": "server2"
}
ok: [host] => (item=server3) => {
"msg": "server3"
}
ok: [host] => (item=server4) => {
"msg": "server4"
}
TASK [Test connection to SCOM_MGMT_SRV_PROD: ['server1','server2','server3','server4']] ***
ok: [host] => (item=server1)
ok: [host] => (item=server2)
ok: [host] => (item=server3)
ok: [host] => (item=server4)
Solution 2:
Meanwhile I've found out that it is possible to Looping over inventory and if I use
with_items:"{{ groups['SCOM_MGMT_SRV_PROD'] }}"
together with a group in inventory file
[SCOM_MGMT_SRV_PROD]
server1
server2
server3
server4
Since the monitoring servers are not part of infrastructure which is maintained by Ansible, Linux admins, etc., I do not like to include them in the inventory other than in a variable.
Are there any other options to loop over a variable list of servers? ... if not, it might be necessary to go with this as solution.
Post a Comment for "How To Use Ansible Module Wait_for Together With Loop?"