# restrict playbook execution from specific directory

**URL:** <https://forum.ansible.com/t/restrict-playbook-execution-from-specific-directory/38303>\
**Category:** Ansible Project\
**Created:** [August 4, 2023, 9:21pm UTC](https://forum.ansible.com/t/restrict-playbook-execution-from-specific-directory/38303 "2023-08-04T21:21:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_T](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@K\_T](https://forum.ansible.com/u/K_T)\
**Post date:** [August 4, 2023, 9:21pm UTC](https://forum.ansible.com/t/restrict-playbook-execution-from-specific-directory/38303/1 "2023-08-04T21:21:10Z")

</div>

Hi,

Is there a way to restrict playbook execution from specific directory?

For example: I don’t want user to execute playbook from home directory and I want to enforce it to be executed from only defined ansible directory

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 7, 2023, 2:47pm UTC](https://forum.ansible.com/t/restrict-playbook-execution-from-specific-directory/38303/2 "2023-08-07T14:47:41Z")

</div>

Not an explicit feature, but I can think of a few ways you could do this:  
- Have an assert/fail at the start of the playbook that checks  
``playbook\_dir`` is in the 'allowed paths'.  
- Setup selinux/apparmor policies to restrict what files  
ansible-playbook can access.  
- Add to the check to a custom plugin you always load (callback/connection/?).  
- Use a wrapper script or shell alias function that does the check and  
then calls the 'real' Ansible CLI.

---

<div class="post-metadata">

**Author:** ![K\_T](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@K\_T](https://forum.ansible.com/u/K_T)\
**Post date:** [August 7, 2023, 5:17pm UTC](https://forum.ansible.com/t/restrict-playbook-execution-from-specific-directory/38303/3 "2023-08-07T17:17:00Z")

</div>

Thank you Brain.

Any sample wrapper script for callback
