Saturday, May 4, 2019

Ansible: Installation and Configuration

Ansible is an open-source software provisioning, configuration management, and application deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. Before proceeding for the installation, it is necessary to get yourself comfortable with basic knowledge.

Ansible Wikipedia: https://en.wikipedia.org/wiki/Ansible_(software)
Official Documentation: https://docs.ansible.com/ 

1. Ansible installation

1.1.  Through pip

The easy way to install ansible is through pip, which is a python package manager.
Prerequisite:
> For before installing ansible, make sure that python3 is already installed.  
> Once Python3 is installed go ahead to install pip
    Sudo easy-install pip3
> Now install ansible through pip3
    pip3 install ansible

1.2.  Through apt (ubuntu)

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt-get install ansible

2.  Basic Configuration:

If ansible is installed manually through pip, the ansible_host inventory file needs to be created manually. Following this you also need to check the reachability of remote servers.

2.1. Adding host file if NOT present

If the ansible is installed using pip3, you will not find any host inventory in the directory /etc/ansible/hosts

if you execute the command ansible webservers --list-hosts this will give an error something like "unable to parse the inventory file in /etc/ansible/hosts". This means that no directory named ansible in /etc/ directory is present. For this follow steps below:

1: cd /etc/
2: sudo mkdir -p ansible/hosts/
3: vim ansible_host
[localhost]
127.0.0.1
[webservers]
[dbservers]
[myhomepage]
[testservers]

4: now enter the command ansible testservers --list-hosts
This will list the webservers that are listed in the group called [testservers]

2.2. Connecting to remote host using ssh


1: open the ansible_host inventory file
vim /etc/ansible/hosts/ansible_host
2: add the following host group or host
[myhomepage]
160.153.137.40 ansible_port=<sshport#> ansible_user=username1 ansible_ssh_pass=user1password

It is assumed that you are able to login to that remote using ssh and using above credentials.
3: now save the ansible_host file
4: enter following command
ansible myhomepage -m ping

2.3. Disabling ssh key host checking

Open the config file in /etc/ansible/ansible.config
Find for #host_key_checking = false. Uncomment the line to make it enable.
[src]: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#latest-releases-via-pip

-Thats all for now.

2 comments: