简体   繁体   English

安装 python pip 模块仅供 Ansible 使用

[英]Install python pip modules only for use by Ansible

I am using Ansible from a pipeline agent, to configure Ubuntu VMs and I would like to use the azure_rm_storageblob and mssql_script module directly on the Ubuntu VM that I am configuring.我正在使用来自管道代理的 Ansible 来配置 Ubuntu VM,我想直接在 Z3D945423F8E9496C429A5D8 上使用azure_rm_storageblobmssql_script模块I had some issues running this, because the packaging module was not installed on the hosts.我在运行它时遇到了一些问题,因为主机上没有安装打包模块。

Is there a way to install the pip modules only for use when I run Ansible (maybe a virtual environment), as I don't want to mess with the pip modules that are installed on the server for other purposes.有没有办法安装 pip 模块,仅在我运行 Ansible(可能是虚拟环境)时使用,因为我不想弄乱 pip 模块上安装的其他目的。

If this is done using something like a python virtual env, how do I make sure that this is used when I connect to the VM using Ansible?如果这是使用 python 虚拟环境之类的东西完成的,我如何确保在使用 Ansible 连接到 VM 时使用它?

You have to use virtual environments to solve that problem ( link to the python doc)您必须使用虚拟环境来解决该问题(链接到 python 文档)

First you create the environment with:首先,您使用以下命令创建环境:

python -m venv venv

Then depending on your OS, you have to activate you virtual environment, on Unix you can do:然后根据您的操作系统,您必须激活虚拟环境,在 Unix 上,您可以执行以下操作:

source venv/bin/activate

The name of you virtual env should be written in your terminal, at that point you know you are using it and not the default python env.您的虚拟环境的名称应该写在您的终端中,此时您知道您正在使用它,而不是默认的 python 环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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