Let’s configure our first playbook!

First and foremost Ansible requires ssh on the devices to be configured I have linked connection here on how to do that.

Ansible can be installed on the following platforms:

Red Hat, Debian, CentOS, macOS, any of the BSDs. Windows is not supported currently.

Bare in mind you also need Python 2.7 or above installed.

Once you have installed Ansible it will create the following default directories of installation:

Note – (I have elevated my user level to root so that I won’t have to input the sudo command all the time – It would not be a good idea to do this in production for security purposes however.)

cd /etc/ansible

Within  this directory you will see two files listed:

ansible.cfg and the hosts file

ansible1

These are the default files that are installed for ansible, you will note a lot of it is commented out, these are some options available and can be used as a template guide.

ansible2

Within the hosts files we can see the formatting as well, this gives you a basic understanding of the layout.

ansible3

We will however create our own directory and within it create our own ansible.cfg and hosts files

So let’s go ahead and create a new directory:

Step 1:

Create a new file directory to store our ansible files, in this example I have create a folder called Ansible_Automation

ansible4

Step 2:

Create the ansible.cfg and the hosts files

ansible6

Within the file type the below configuration

ansible7

Next we will configure our hosts file

ansible9

Within the file type the bellow configuration

ansible10

In my example I have just used two ios devices , however you can populate this with hundreds of devices, you can see the possibility of automation scales at work. (Something that takes time configuring hundreds of devices can literally take you minutes)

Step 3:

Create our playbook!

All we need to do is create a file with a .yml extension (Yaml – Yet another markup Language)

In my case I called it (myfirstplay.yml)

What this basic playbook will do is to run the command : show version on our switch and display the content.

Generally you would not want to pass any credentials through the playbook however in this case we are doing it as an example to speed up the process. (Remember our details in our ssh setup)

ansible5

Within the file type the below configuration

ansible11

Now that we have configured it, it’s time to run it!

Step 4:

Let us run our first playbook by typing the below:

ansible13

ansible14

This completes our first basic tutorial on how to setup a playbook in ansible