I have a playbook that targets a small set of hosts, and a task there that changes some configuration files on one or more of these hosts, depending on how I've set my variables.
A simplified example result of running this task:
TASK [somerole : create config file] *************************************
ok: [server1] => (item=foo.conf)
changed: [server2] => (item=foo.conf)
changed: [server3] => (item=foo.conf)
If I use register
on this task and then debug
the variable it creates, the output of the debug: var=varname
would look something like this (considerably simplified):
TASK [somerole : debug] **************************************************
ok: [server1] => {
"varname": {
"changed": false,
"results": [{...}]
}
}
ok: [server2] => {
"varname": {
"changed": true,
"results": [{...}]
}
}
ok: [server3] => {
"varname": {
"changed": true,
"results": [{...}]
}
}
The config change necessitates a service restart that currently has to be done manually by a human (there's a manual eyeballing validation step). To help with this, I would like to use the pause
module at the end of the playbook to display a prompt to the user, looking something like this:
- pause:
prompt: |-
The configuration has changed on the following servers: {{ changed_servers|join(', ' }}
Please restart service X on these servers after validating Y and Z.
So, how do I build the changed_servers
variable? Given the examples above, it would be this list:["server2", "server3"]
(since they were the hosts changed by the task this time).
I first thought I'd try to combine the varname
variable that register
produced for each host affected by the task, looking at the changed
boolean in each, but the name of the host is not present anywhere inside varname
so that I could combine the changed
attribute with the name of the corresponding host.
Is there actually a way to do this?