Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Ansible is written in Python and all its modules need Python to be installed on the Ansible control machine. Our first task is to ensure that Python is installed on the Ansible control machine, as outlined in the following steps.

  1. Most Linux distributions have Python installed by default. However, if Python is not installed, here are the steps for installing it on Linux:
    •  On an Ubuntu OS, execute the following command:
# Install python3
$sudo apt-get install python3

# validate python is installed
$python3 --version
Python 3.6.9
    • On a CentOS OS, execute the following command:
# Install python
$sudo yum install pytho3

# validate python is installed
$python3 --version
Python 3.6.8
  1. After we have validated that Python is installed, we can start to install Ansible:
    • On an Ubuntu OS, execute the following command:
# We need to use ansible repository to install the latest version of Ansible
$ sudo apt-add-repository ppa:ansible/ansible

# Update the repo cache to use the new repo added
$ sudo apt-get update

# We install Ansible
$ sudo apt-get install ansible
    • On a CentOS OS, execute the following command:
# We need to use latest epel repository to get the latest ansible 
$ sudo yum install epel-release

# We install Ansible
$ sudo yum install ansible