I am looking for a when
condition which is fullfilled when the playbook is executed by ansible-pull.
1 Answer
I found two approaches to test if a playbook is applied via ansible-pull
:
- Check for
ansible_connection == "local"
. However this doesnt work in all places as local connections might also used regularily by your playbook. - Pass an extra variable to the invocation:
ansible-pull --extra-vars "ansible_pull=true"
ansible-pull
actually runsansible-playbook
internally with no particular option once SCM checkout is done (run with-vvv
to see the steps). If you use a specific directory on all your servers to clone your playbook repos fromansible-pull
, you can eventually set a condition on theplaybook_dir
variable. This is way far from bulletproof though.