I have a silly playbook which just runs a command to get the list of vhost in every host on webserver group. As all vhost are located in /var/www is easy to get the list of webs.
The problem is the way of Ansible returns the info. For example:
ok: [host1] => {
"var": {
"out.stdout_lines": [
"",
"host1.com"
]
}
}
ok: [host2] => {
"var": {
"out.stdout_lines": [
"",
"host2.com"
]
}
}
Do you know an easy way to just get the name of the vhosts? Using grep awk or something like that?
Dirty way: prepend each line in stdout_lines
with some marker (e.g. ANSBLMRK_
) before printing, so you have a list if "ANSBLMRK_host2.com", then grep
and cut
.
Good way: set ANSIBLE_STDOUT_CALLBACK=json
and pipe it to jq
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With