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 agentless. Yes you read it right it is clientless and developed in python language. Ansible architecture is very simple which made by a manager which must be linux and the systems managed which may be linux, bsd or windows. There are some differences in windows but it is not a problem after setup ansible. All systems managed by the same way. In linux and bsd connection made over ssh but in windows rmi protocol. This is enough lets start typing commands.

Install Ansible

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

1

$sudo yum-yinstallansible

Passwordless Connection

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

1

2

3

4

5

6

7

$ssh-keygen

Generating public/privatersa key pair.

Enter file inwhich tosave the key(/home/ismail/.ssh/id_rsa):

Enter passphrase(empty forno passphrase):

Enter same passphrase again:

Your identification has been saved in/home/ismail/.ssh/id_rsa.

Your publickey has been saved in/home/ismail/.ssh/id_rsa.pub.

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

Inventory and Hosts

Add this host (192.168.122.165) to the ansible host inventory . Here myex is group name which covers hosts listed below. For now I just add one host

1

2

3

4

$sudo vim/etc/ansible/hosts

[myex]

192.168.122.165

Ping Hosts and Check Connectivity

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

1

2

3

4

5

$ansible myex-mping

192.168.122.165|success>>{

"changed":false,

"ping":"pong"

}

Run Ad Hoc Command

We can specify pure commands to run on remote system with -a option.

1

2

$ansible myex-a"mkdir ~ismail/ansible"

192.168.122.165|success|rc=>>

If we need to debug ansible work we can use -vvv flags where count of v decides the debug level. As you can see below connection username and 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 is ansible verbs EXEC, PUT etc.