I use Ansible to deploy a systemd unit file to all the servers in an estate and enable it to start on boot. On some of those servers, the binary defined in the unit file is on a different filesystem. This requires the unit file to have a dependency on that filesystem being mounted. E.g.:
[Unit]
Description = Start the widget
After = network.target usr.mount
[Service]
Type = simple
ExecStart = /usr/bin/widget
[Install]
WantedBy = multi-user.target
Currently the unit file is deployed by Ansible as a static file, using the ansible.builtin.copy module. Is there a way I can convert this to a template and append the mountpoint to After = if /usr is a mountpoint?