Hi,
I’ve got a play that consists of a number of roles, like so:
`
- name: Ble
hosts: hosts
sudo: yes
roles:
- role1
- role2
- role3
`
In role2, I’ve got a handler that reboots the hosts and I need role3 to wait for the hosts to come up before starting (or role2 to somehow wait before exiting), and I’m not sure how to do this.
I know I have to use the ‘wait_for’ module, but I’m not sure where to put it. Should (can?) I put in the handler or should it be at the start of role3 or should I just skip the handler, insert a reboot + wait_for at the end of role2?
Any help appreciated.
/M
This should do it for you:
- hosts: role3
tasks:
- wait_for: host={{host}} port=22
with_items: servers_to_wait_for
Thanks, I'll try that.
So I guess I can somehow reference the hostgroup 'hosts' (which was a stupid name even for an example...) in the with_items section then, since the number of servers may change?
/M
groups[‘groupname’]
is a list of all hosts in a group, so
with_items: groups[‘groupname’]
will do it.
Awesome, thanks!
So given:
[dbservers]
Node1
Node2
Is there a way to (in the play) get info on which group the play is running against?
I.e something that will tell me 'dbservers'?
Or is that something I have pass in as a variable?
/M
“Is there a way to (in the play) get info on which group the play is running against?”
In recent versions, should you need this, the variable “play_host” contains the list of all hosts currently being targetted.
There is no variable that gives you the host specifier, which is largely ok, because you also have no function that would resolve it.
I’m curious as to why it would be needed.
Ok,
In this case its because [cluster1] makes up one cluster of dbservers and [cluster2] is another cluster, and those identifiers are used as the cluster-name for each config. But those can easily be passed in as a parameter so its not really a problem.
I just ran a few tests and noticed that the variable ‘group_names’ does contains the hostgroup [cluster1]
`
- name: test
debug: msg="Running against hostgroup {{ group_names }} "
with_items: groups[‘cluster1’]
Output (snipped):
ok: [node1] => (item=node1) => {
“item”: “node1”,
“msg”: "You are running against hostgroup [‘cluster1’] "
}
ok: [node2] => (item=node1) => {
“item”: “node1”,
“msg”: "You are running against hostgroup [‘cluster1’] "
…
`
Anyway, thanks for the help.
/M