What Is Ansible and How to get started

We’ve all heard about this term “Ansible Automation”, “Ansible can do this” or “Ansible could be used to automate our operations”, so we start by asking our ‘Best Friend’ aka ‘The place where all questions are answered’, which is GOOGLE.

So, we start Googling “Ansible automation” or “Ansible tutorial” or maybe “How to automate using ansible”, then proceed to watch some videos from YouTube hoping to gain some knowledge on what is Ansible all about but consciously we realized, it all ends there, and we carry on our work-life not knowing how to ansible could help our day to day operation works.

What is Ansible?


I’m pretty sure you’ve scrapped through the whole Google and the answer to this question is always the same, “Ansible is a configuration tool which is agentless and works via SSH/API/WinRM blah blah blah”.

I’m not going through that to bore you, so let me tell you my definition of Ansible, it is simply an “Automation tool”. Now I’m pretty sure you’ll be like, “this guy is a joke! You think I’m so dumb to not know!? Oh, c’mon”.

Hold your horses, my friends, let me explain, the key takeaway here is that I want you guys to understand, Ansible is a tool where people from different aspect of IT field, collaborate together to create different functions to perform on a device using Python then these functions are translated to human readable language which is YAML.

Ansible is an open-source tool in which contributors from different aspects of the IT field have gone through the hardship to develop these “functions” what we call in Ansible is “modules” using Python which he/she then decides to contribute back to the community for others to utilize.

Don’t Reinvent the Wheel, Unless You Plan on Learning About Wheels

Getting Started with Ansible


Ok…. Now we know that someone has created these “functions” for us then now what? The fun thing is rather than getting an answer here, why not ask yourself, that question instead?

Which are the most boring, repetitive and brainless workflow which you’re tasked to do but your first reaction is “Shit! I have to do it again!? Oh, C’mon it’s so boring! My life sucks”

What is the workflow which is so static that you could do it in another environment with the same steps to provide the same output?

Lastly, what are the workflows which you feel like you’re transforming into a 1980s Robot?

These are the workflows that you could recite it out, step by step by head without a document to follow. Instead of reciting it out, why not transfer all these workflows into individual files, store it somewhere and when we need it, let Ansible do it for us. In Ansible, we call this “file” a playbook.

An example of a playbook which is a clear explanation of boring workflow is “Backup Cisco Device Configuration”, this is the most static, boring and time consuming workflow but sorry to say it is needed as to ensure that we will have the most updated configuration copy when restoring the device.

  1. Ensure that Local directory is created
  2. Connect to device and issue “show run” command
  3. Save output to local directory

cisco_ios_backup.yml

---
- hosts: cisco
  gather_facts: no
  connection: local
  
  tasks:
- name: Creates directory
  file:
    path: "/opt/cisco"
    state: directory
    mode: u=rwx,g=r,o=r
 
- name: Issue "Show Run" command
  ios_command:
     commands: show run
   register: run
 
- name: Saving Config to local
  copy:
    content: "{{ run.stdout[0] }}"
    dest: "/opt/cisco/{{ inventory_hostname }}"

inventory file

---
[cisco]
cisco1 ansible_host=10.10.10.1 ansible_network_os=ios
cisco2 ansible_host=10.10.10.2 ansible_network_os=ios
cisco3 ansible_host=10.10.10.3 ansible_network_os=ios

How Ansible works is that it will have based on the specified inventory file, for each device stated in it, run this playbook in sequence. Tadah, jobs done! Boring stuff bye-bye!

Just imagine the pain you have to go through using the traditional method every day in the morning and the most sickening part is that I have 500 devices to backup!

It never ends here….

There are many modules and commands available to be executed on the remote host with Ansible. Instead of asking Google what Ansible can deliver, why not start Googling “Using Ansible to backup Cisco device” “Use Ansible to mass provision ESXi VMs”.

Start googling the use case rather than asking what the automation tool can deliver and start documenting your workflow rather than expecting Ansible to know the workflow. Tell Ansible what you want to do rather than expecting Ansible to know what to do.

Design a site like this with WordPress.com
Get started