If you ever wanted to manage multiple servers in your data center from a centralized location, ansible is the right choice when it comes to automation and orchestration of network infrastructure. This is really core of NetDevOps. It quotes
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.
In this lesson, we will learn to install & configure ansible on your ubuntu machine 18.04 LTS. So lets get started.
First of all login to your Ubuntu machine with sudo privilege users and update / upgrade the repositories.
sudo apt update && sudo apt upgrade -y
Ansible depends on Python in order to run its modules, so lets install python on our ubuntu server if not already installed.
sudo apt-get install python -y
Before proceeding for installation of ansible, add the following repositories to your ubuntu machine and update apt again to take affect & then install it.
|$sudo apt install software-properties-common|
$sudo apt-add-repository ppa:ansible/ansible
$sudo apt-get update
$sudo apt install ansible -y
Once installation is done, you can check its working by running the ping module against localhost
|$ansible localhost -m ping|
Following response should appear if ansible is installed properly.
Setting-up Ansible Node & SSH Access
At this point Ansible is installed, now we need to configure it. Start by adding remote servers IP address which needs to be managed in our ansible server’s hosts file.
|$sudo nano /etc/hosts|
Next, generate SSH keys on ansible server by issuing below command.
Now transfer the keys to remote hosts which you want to manage but before executing below command, SSH server must be installed & enabled on remote hosts. Assuming that on remote server SSH service is enabled perform below task.
|ssh-copy-id -i .ssh/id_rsa.pub ubuntu|
ssh-copy-id -i .ssh/id_rsa.pub centos
Now ansible server must have SSH access to these hosts, now we need to provide ansible user sudo access without any password. To do so, login to each server and perform following steps.
at the bottom of visudo fiel add following line with username of ansible server which is in my case “techacad”.
|ANSIBLE_USERNAME ALL=(ALL) NOPASSWD: ALL|
save and exit the file. Next Add these nodes to ansible inventory by editing /etc/ansible/hosts file with your favorite editor.
Additionaly you can also specify username to use, like so.
save & close the file, now to check wheter ansible is able to reach nodes in its inventory, execute:
|ansible -m ping all|
That’s it, Congratulations, Ansible is now installed and communicating with nodes in its inventory. In this lesson we learnt how to install & configure ansible on ubuntu server. Now You’re now ready to start creating playbooks.