I currently have three ansible tasks:
- create vhosts
- test config
- reload nginx
I now registered the last two as handlers, but the forward notifications of ansible feel wrong for what i am doing:
- create vhosts, notify test config (okay)
- test config, notify reload (why does a config test imply a reload)
- reload nginx
I would like a structure like:
- create vhosts, notify nginx reload
- nginx reload: require config test
- config test: success
- nginx reload
Just because the semantics seem more correct. It should be neither just a sequence, nor should something like a config test notify a reload, because this is just implementing a sequence again without logic behind (like a reload requires a test first)
A simple conditional in your playbook with the use of
when
should work, in case you are ignoring errors. As by default, Ansible playbook run terminates when it encounters an error. Nginx configtest exits with shell status code of0
on success and1
on failure, and you can use that to run different tasks depending on the result -