With systemd 263 heading toward release, I wanted a quick look at which systemd version every box I manage is actually running. Arch picks up new releases fast, while Debian stays put for years. Ansible ad-hoc commands make that a one-liner, no playbook needed.
1. The quick version
ansible all -m ansible.builtin.shell -a "systemctl --version | head -n1" -o
The -o flag gives you one line per host, with the version number and the distro’s build string, which is easy to scan or pipe into sort.
2. Group the results by version
ansible all -m ansible.builtin.shell -a "systemctl --version | head -n1" -o \
| awk '{print $(NF-1), $NF}' | sort | uniq -c
Now you can see at a glance how many boxes are on each version.
3. Check for failed units while you’re there
ansible all -b -m ansible.builtin.command -a "systemctl --failed --no-legend --plain" -o
An empty result means nothing has failed. Anything listed is worth a look before the next big update lands on top of it.
4. Confirm it’s really systemd
ansible all -m ansible.builtin.setup -a "filter=ansible_service_mgr" -o
That’s handy if you’ve got a container, an Alpine box or a BSD in the inventory that doesn’t run systemd at all.
Notes
- These are read-only commands. Nothing changes on the hosts.
- Limit the run to one group with
ansible webservers ...instead ofall. - Release candidates like 263-rc1 belong on test boxes. Let your distro ship the final release.
God Bless, and Use the Source!