Introduction
What is Ansible ?
Ansible
is an open-source configuration management, software provisioning and application deployment tool that makes automating your application deployments and IT infrastructure operation very simple. It is an agentless solution and easy to configure unlike other automation tool like Puppet
or Chef
Installation
Ansible rely on SSH and Python to do all automation and so you only need to install Ansible on the control node and make sure that OpenSSH and Python is installed on both the control (Where the Ansible is install) and the node (host which needs to be configure). When configuring network equipments, there is another way to configure node since it isn’t possible to install python (Python 3 recommended) on these host.
Here are some way to install Ansible :
- via PIP
- via binary
- via repository
- docker
PIP
sudo apt install python3-pip
VERSION=3
pip install ansible==$VERSION
ansible --version
Binary
git clone https://github.com/ansible/ansible.bit
cd ansible
source ./hacking/env-setup
sudo apt install python3-pip
pip install --user -r ./requirements # Module installation for Jinja
Repository
apt-add-repository --yes --update ppa:/ansible/ansible-2.9
sudo apt install ansible
ansible --version
Notes and Recommendations
Even though you can use the root user in Ansible to run Ad-Hoc commands and playbooks, it is not considered a best practice due to the security risks that can arise bys allowing root user ssh access. For this reason, it’s is recommended to create a dedicated Ansible user with sudo privileged on every node and on the manager.
useradd -m aubin
echo "aubin ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
Now configure the SSH Key to access node without using password
ssh-keygen
ssh-copy-id node[1-x]
Set Python3 as the default interpreter for Ansible. You could link from /usr/bin/python
to python3
or you could set the value of ansible_python_interpreter=/usr/bin/python3
in the ansible.cfg
file.