<p>I found two approaches to test if a playbook is applied via <code>ansible-pull</code>:</p>
<ol>
<li>Check for <code>ansible_connection == &quot;local&quot;</code>. However this doesnt work in all places as local connections might also used regularily by your playbook.</li>
<li>Pass an extra variable to the invocation: <code>ansible-pull --extra-vars &quot;ansible_pull=true&quot;</code></li>
</ol>

CC BY-SA 4.0
2021-08-23T09:46:36.503Z
2021-08-23T09:46:36.503Z
Steffen Vogel
<p>I am looking for a <code>when</code> condition which is fullfilled when the playbook is executed by ansible-pull.</p>

CC BY-SA 4.0
2021-08-14T21:12:27.960Z
I'm affraid you can't since `ansible-pull` actually runs `ansible-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 from `ansible-pull`, you can eventually set a condition on the `playbook_dir` variable. This is way far from bulletproof though.
Zeitounator
<ansible>
How can I detect if an Ansible playbook is executed by ansible-pull rather than ansible-playbook?
Steffen Vogel
# How can I detect if an Ansible playbook is executed by ansible-pull rather than ansible-playbook?

(Asked by: username_0 on 2021-08-09)

I am looking for a `when` condition which is fullfilled when the playbook is executed by ansible-pull.

**Tags:** ansible

> **Comments:**
> **username_1**: I'm affraid you can't since `ansible-pull` actually runs `ansible-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 from `ansible-pull`, you can eventually set a condition on the `playbook_dir` variable. This is way far from bulletproof though.  

---

## 1 answers

### Answer by username_0 on 2021-08-23. Score: 1

I found two approaches to test if a playbook is applied via `ansible-pull`:

1. Check for `ansible_connection == "local"`. However this doesnt work in all places as local connections might also used regularily by your playbook.
2. Pass an extra variable to the invocation: `ansible-pull --extra-vars "ansible_pull=true"`


---

