简体   繁体   中英

how to run python script in ansible playbook using virtual enviroment?

I'm trying run python script test.py using a virtual environment. in standard Linux bash it simply looks like

source venv/bin/activate
screen -dm  python3 test.py

But how I can do the same using ansible-playbook?

When you create a virtual environment in python, a 'python3' interpreter is added in the 'bin' folder of the virtual environment (venv/bin/python3). This interpreter has all the dependencies/packages that you've installed using pip for the project.

So, if you want to execute a script using this interpreter, you can provide the complete path to the interpreter.

Example: Consider the python file: test.py Name of virtual environment: venv Command to execute the script: venv/bin/python3 test.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM