What is Ansible and How to install and configure Ansible ?

What is Ansible and how to install Ansible ?

  1. Ansible is a Automation tool. It used to configure systems, deploy softwares and it also provide zero downtime rolling updates.
  2. Ansible was design to make simple and ease to use. And also focused on security and reliability. Ansible uses SSH connection for transport.
  3. Ansible ease, simplify the work of all users such as developers, sysadmin, and release engineers etc.
  4. It can be used to handle all type environment from small to very large enterprises.
  5. It can easily be connected with Kerberos, LDAP, and all type of centralized management systems.

How to install Ansible and what are its requirements ?

We need epel-release repository, git, python, pip, openssl and then ansible

Command to install ansible with its requirements

yum install epel-release && yum install git python-devel python-pip openssl ansible

Check the install of ansible and it will also show the path to its configuration and hosts file

ansible –version

Now edit the ansible configuration file

vim /etc/ansible/ansible.hosts
uncomment
inventory = /etc/ansible/hosts
sudo_user=root #enabling the sudo permissions

Now edit the hosts file

vim /etc/ansible/hosts
mv hosts hosts.original

Create a new host file

vim hosts



[local]
localhost
[centos]
techouse.labserver.com
[ubuntu]
dtlegal.labserver.com

Create a new user for ansible

useradd ansible

Authenticate user with password

passwd ansible

Give user permission as sudo user.

How to give sudo permission too any user.

visudo

For centos

ansible ALL=(ALL) NOPASSWD: ALL

For ubuntu

ansible ALL=(ALL) NOPASSWD: ALL

Ansible SSH connection should be setup through key exchange if use ansible through password then its not possible to work with password because every time connection will break.

ssh-keygen
su – ansible
ssh-cop-id [email protected]
ssh-cop-id [email protected]

Check the hosts file again

cat /etc/ansible/hosts

Now we will run ansible commands with its options and will test our clients system

ansible all -a “ls -al /home/ansible”
ansible all -m ping

Now there is one scenario , How to run command with sudo privilages
Answer is Use option -s (run command with sudo permission)

ansible all -s -a “cat /var/log/messages”

How to run command for single user

ansible username -s -a “cat /var/log/messages”
ansible localhost -s -a “cat /var/log/messages”

=============================

How to copy file using copy module



ansible centos -m copy -a “src=test.txt dest=/tmp/test.txt”

How to install packages using ansible

ansible centos -m yum -a “name=elinks state=latest”
ansible centos -s -m yum -a “name=elinks state=latest”

How to remove and install package

ansible centos -s -m yum -a “name=elinks state=absent”

How to create user using ansible

ansible centos -m user -a “name=test”

How to remove user using ansible

ansible centos -m user -a “name=test state=absent”

 

Important Links

Ansible official page.

Create user in Linux

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.