Notifications at the end of just target

George Shuklin
OpsOps
Published in
1 min readFeb 3, 2023

If you run Ansible via just ( as I do) you may want to see notification about completion at the end of the long playbook.

I wrote an article about how to do it for plain Ansible run

Tl; dr;

ansible-playbook site.yml; notify-send -u critical "ansible has finished"

But I wanted to put it into Justfile, in a way which does not break Macs or CI servers (without GUI and notify-send).

With a small Just magic it become this:


reinstall:
ansible-playbook reinstall.yaml
-@which notify-send >/dev/null && notify-send -u critical "Ansible has finished"

The main magic is ‘-’ at the beginning, which hide errors. If notify-send binary is not found, notification is not send, and error message from which is ignored (both as text and as exit code). && is a usual bash ‘if first command is ok, run second’ (shortcut boolean expression).

@’ is the second Just magic, hide command text from output.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.