0

I'm currently using the ad-hoc command ansible ubuntu -a "ls -l /var/run/reboot-required" to get a list of servers that require reboot. However, the end result is a list of all servers, and either the info about the indicated file or an error that the file does not exist.

I'm familiar enough with playbooks to create one that actually does the reboot, but I don't want that. I just want a nice (and relatively neat) list of servers that still require a reboot.

A more generic solution of getting a list of servers that meet some criteria (e.g. have a variable set) would also be quite helpful.

Elros
  • 313
  • 1
  • 3
  • 10

1 Answers1

0

Not easy because the proper way is checking the existence of the file with stat, saving it to a variable and create a list when: var.stat.exists.

If you want to do in one line and you don't mind using bash scripting, do:

ansible ubuntu -m stat -a "path=/var/run/reboot-required" -o | grep -v '{"exists": false}' | awk -F\| '{ print $1 }'

Hope it helps

imjoseangel
  • 3,543
  • 3
  • 22
  • 30