Introduction To Ansible Tutorial – POFTUT

Introduction To Ansible Tutorial

Hi today we will look to a system management automation tool named Ansible. There is a lot of tool in this category but Ansible is different with being agent-less. Yes you read it right it is client-less and developed in python  language. Ansible architecture is very simple which made by a manager which must be Linux and the systems managed which maybe Linux, BSD or Windows. There are some differences in windows but it is not a problem after setup Ansible. All systems managed in the same way. In Linux and BSD connection made over ssh but in windows RMI protocol.

Install Ansible

Firstly we use fedora for the manager and we should install ansible only on this system. Below command install ansible on the manager

Ubuntu, Debian, Mint, Kali

Ubuntu, Debian, Mint, Kali

Ubuntu, Debian, Mint, Kali

Fedora, CentOS, RHEL

Password-less Connection

And then create ssh-id if it doesn’t exist. We can skip key generation questions to enter without giving any value.

Password-less Connection

Password-less Connection

Than we will install the keys to the remotely managed system with ssh-id-copy command. Now we are ready to use ansible in a simple way.

Inventory and Hosts

Ansible uses its host’s file which is named as Inventory to get information about remote systems. We can group hosts in this inventory file. Add this host (192.168.122.165) to the Add host inventory . Here myex is group name which covers hosts listed below. For now I just add one host

LEARN MORE  How To Start Applications From Command Line In Windows Different Ways?

Inventory and Hosts

Inventory and Hosts

Ping Hosts and Check Connectivity

Now we can use ansible. We use the ping module with -m option ans by specifying the group name. We can use all for all inventory hosts.

Ping Hosts and Check Connectivity

Ping Hosts and Check Connectivity

Run Ad Hoc Command

We can specify pure commands to run on a remote system with -a option. Ad Hoc command provides us the ability to run a command on the remote systems. In this example, we will print the passwd file with cat command.

Run Ad Hoc Command

Run Ad Hoc Command

Debug Ansible and Verbose Output

If we need to debug Ansible work we can use -vvv option where the count of v decides the debug level. As you can see below connection username and the remote module is specified and than ssh connection is made with specified parameters if you have a problem with ssh connection you can find detailed info about the problem here. There are Ansible verbs EXEC, PUT, etc.

Debug Ansible and Verbose Output

Debug Ansible and Verbose Output

Run Sudo On Remote System

We can use sudo privileges on the remote system with --sudo and specify sudo user with –sudo-user .

Ansible Configuration

Because ansible use ssh we can disable ssh host key checking by uncommenting below the line.

LEARN MORE  How To Use mRemoteNG For RDP, VNC, SSH Remote Connections?

Sometimes there are a lot of systems to manage and run commands. We can make ansible work parallel with -f option

Leave a Reply

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