
上QQ阅读APP看书,第一时间看更新
How it works...
In order to install Ansible in a Python 3 environment and to have more control over the version of Ansible deployed, we are going to use the pip Python program to install Ansible as shown here:
- Install Python 3 if it is not present, as follows:
# Ubuntu
$ sudo apt-get install python3
# CentOS
sudo yum install python3
- Install the python3-pip package:
# Ubuntu
$ sudo apt-get install python3-pip
# CentOS
$ sudo yum install python3-pip
- Install Ansible:
# Ubuntu and CentOS
# This will install ansible for the current user ONLY
$ pip3 install ansible==2.9 --user
# We Can install ansible on the System Level
$ sudo pip3 install ansible==2.9
- We can verify that Ansible has been installed successfully, as shown here:
$$ ansible --version
ansible 2.9
config file = None
configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/vagrant/.local/lib/python3.6/site-packages/ansible
executable location = /home/vagrant/.local/bin/ansible
python version = 3.6.8 (default, Aug 7 2019, 17:28:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Installing Ansible using this method ensures that we are using Python 3 as our execution environment and allows us to control which version of Ansible to install, as outlined in the example shown.
We are going to use this method as our Ansible installation method and all the subsequent chapters will be based on this installation procedure.
In Chapter 13, Advanced Techniques and Best Practices for Ansible, we will outline yet another method for installing Ansible using Python virtual environments.