I'm running ansible-playbook via something like
subprocess.run(['bash', '-c', "ansible-playbook some_playbook.yml"])
After uninstalling & reinstalling ansible-playbook my project somehow can't execute it anymore claims "bash: ansible-playbook: command not found".
Facts:
- running on Ubuntu 20.04
ansible-playbookwas installed viapip3
Tried the following:
ensured that the command is available and runnable via terminal &
python3deleted the
venvfolder and reinstalled everything (using PyCharm does it automatically)deleted Bash cache via
hash -r&hash -d ansible-playbookrebooted
installed
pycleanand ran itdeleted
.ideafolder (PyCharm)recloned the repository into different directory and set up everything again. Same problem.
created a dummy test in the same project folder and found out that it runs fine:
> cat test.py import subprocess process = subprocess.run(['bash', '-c', "ansible-playbook some_playbook.yml"])
Everything worked fine before the reinstall. My program also runs various Bash commands before executing ansible-playbook and I swear on my left testicle that it's not my code. There must be some hidden mystery cache I'm missing.
Thanks for any suggestion!
CodePudding user response:
To make my comment an answer:
If you've installed the package as a regular user with a recent pip, it will have installed the libraries and binaries into ~/.local/bin which isn't on PATH by default. (Pip will warn you about that.)
Once the binary is on PATH, you can skip the extra shell process (which is unnecessary and may cause Weird Things in certain situations) and not be vulnerable to shell injection attacks with
import subprocess, shutil
subprocess.run([shutil.which("ansible-playbook"), "some_playbook.yml"])
