I have nginx with php app. I have also installed ansible and copied playbooks on this server. What I want to do is run ansible playbooks through webapp. I want to know how to do this safe way.
Nginx is running under user nginx, php-fpm is running under apache and ansible has it's own user. Php app is in /var/www/html/ and ansible playbooks are in /var/www/html/ansible, but these dirs are readable for everyone.
So the flow should look like:
- user selects action on webpage
- ajax sends it to php
- php prepares ansible command and runs ansible playbook
- ansible runs
- php catches stdout&stderr and sends it back to webpage as json
- ajax will show stdout&stderr on webpage.
Now, in php script, I plan to exec('ansible-playbook site.yml -t ...'). This will be executed as apache user. Or should I start it under ansible's user with sudo? Or better is to start nginx,php-fpm and ansible under nobody?
Not sure what is the best for this.
Thank you for you opinions.