# Not able to execute playbook from php shell\_exec

**URL:** <https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485>\
**Category:** Ansible Project\
**Created:** [October 18, 2019, 4:12am UTC](https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485 "2019-10-18T04:12:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sayantan\_Laha](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@Sayantan\_Laha](https://forum.ansible.com/u/Sayantan_Laha)\
**Post date:** [October 18, 2019, 4:12am UTC](https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485/1 "2019-10-18T04:12:55Z")

</div>

Dear Team,

I have written lots of playbooks for our Network Automation Nxos, ios and ASA.

Now trying call someof our playbooks from php web page using shell\_exec('anisble\_playbok cli command')...

Its throwing an error saying "unable to open shell"

But while executing same playbook from server CLI its working fine.

My doubt while executing from web, its taking user as 'Apache' which is not able to execute this playbook.

Where other users on that same unix server can able to execute that playbook.

So is there any way to change current user or what you suggest as a solution?

I have tried with become but didnt worked for me.

Sayantan Laha

---

<div class="post-metadata">

**Author:** ![Mike\_A](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_A](https://forum.ansible.com/u/Mike_A)\
**Post date:** [October 18, 2019, 4:29am UTC](https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485/2 "2019-10-18T04:29:29Z")

</div>

Hi Sayantan

Not sure if would be the greatest idea from a security perspective to allow PHP to run something as a more privileged user.

Could you not host an API somewhere running as one of those users and the PHP triggers that API which then in turn makes the call?

In terms of actually answering it though, you could execute a one liner to sudo su to your chosen user and pass the command in to execute also.

Not strictly Ansible related though.

Kind regards

Mike

---

<div class="post-metadata">

**Author:** ![Sayantan\_Laha](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@Sayantan\_Laha](https://forum.ansible.com/u/Sayantan_Laha)\
**Post date:** [October 18, 2019, 4:51am UTC](https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485/3 "2019-10-18T04:51:11Z")

</div>

Thanks Mike for your quick revert.  
Yes you are absolutely right, its not very secure, but we used it as an internal application within a team.  
Tried with sudo su , but no luck.

Let me try with API cancept.

Thanks once again.

Sayantan

---

<div class="post-metadata">

**Author:** ![Mike\_A](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_A](https://forum.ansible.com/u/Mike_A)\
**Post date:** [October 18, 2019, 4:54am UTC](https://forum.ansible.com/t/not-able-to-execute-playbook-from-php-shell-exec/31485/4 "2019-10-18T04:54:36Z")

</div>

Did you grant permission for your user to sudo to the privileged user in /etc/sudoers?
