![]() re:=1.2.1 -p collections Deactivate a Python virtual environment For example, to test a specific Ansible Kubernetes.Core collection: (ansible2.9)$ ansible-galaxy collection install \ You can also install Ansible roles and collections into a Python virtual environment path for testing. Setuptools 39.2.0 Install Ansible roles or collections You can now install any libraries or modules within your virtual environment without affecting the rest of your system: (ansible2.9)$ python3 -m pip install dnspythonĭownloading dnspython-2.1.0-p圓-none-any.whl (241 kB) You can see that the Ansible version and path inside your Python virtual environment are different from your system installation. Verify your new installation: (ansible2.9)$ ansible -versionĬonfigured module search path = Īnsible python module location = /home/devops/python-venv/ansible2.9/lib64/python3.6/site-packages/ansibleĮxecutable location = /home/devops/python-venv/ansible2.9/bin/ansible This example installs version 2.9, but you can install any version that's current (or in development): (ansible2.9)$ python3 -m pip install ansible=2.9 With your virtual environment set up and active, you can install a dedicated version of Ansible into it. Next, upgrade the preferred installer program ( pip) inside your virtual environment: (ansible2.9)$ python3 -m pip install -upgrade pip Install Ansible in a virtual environment This changes your active environment variables from your current shell to those required for Python to create a virtual environment: $ source ansible2.9/bin/activate Activate a Python virtual environmentĪfter creating a virtual environment, you must enter the environment manually. ![]() I want to try the Ansible 2.9 version, so I named it in a way to identify the directory easily: $ python3 -m venv ansible2.9 You can give any name to your Python virtual environment. Create a new Python virtual environmentĬreate a virtual environment using the python3 -m venv command. You can skip this part if you want to keep it somewhere random, but I find it helpful to keep my consolidated test directories together. I recommend setting up a directory for the virtual environment: $ mkdir python-venv First, verify the installed Python version and path: # check Python version In this scenario, this is your Ansible development machine. I wrote this article for a Linux computer with Python 3.x. Still, you can have different versions of Ansible and other important Python modules in a dedicated test directory with a virtual environment. Upgrading a component that your production environment depends on defeats the purpose of testing. When you test something new, it could require you to update a module that your Ansible installation depends on. That means you can have different sets of Python environments, each with different versions of modules, files, or configurations.Īnsible is based on Python and leverages many Python modules and plugins. Virtual environments are like a virtual machine or Linux chroot, but they create an isolated structure of lightweight directories separated from actual Python system directories. Automate Red Hat Enterprise Linux with Ansible and Satellite.Ansible Automation Platform trial subscription.A system administrator's guide to IT automation.Ansible Automation Platform beginner's guide.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |