Ansible is an open source configuration management tool. In simple terms, you can use ansible to provision an environment, configure it and deploy it. In this article, we will be discussing on how we use ansible to deploy your code onto the servers.

So what is deployment?

The basic steps to deploy code onto the infrastructure is as follows –

  • Install the servers such as web server, appserver on the Linux/Unix/whatever server you use.
  • Next, get your packages from your artifactory and deploy them on to the servers you’ve installed.
  • Now restart the servers.

These are the basic steps you have to accomplish to get your deployment done. Let’s get to the structure on how we accomplish this using ansible.

Terminology –

Playbook – Is an ansible file that runs the deployment or the tasks required for the deployment. Playbooks file extension is ‘.yaml’ or ‘yml’.

Ansible Control server – The server from which you run the ansible playbooks.

Target servers – The servers on which you deploy the code using ansible.

Ansible.cfg – This file is the config file for your ansible model. You can customize things here.

Group_vars – This is the directory that consists of files that has the key value variable pairs in here.

Inventory – This is the folder where you have files that consists of the server ip’s or names in it.

Roles – Roles is a main directory that has the tasks playbook, handlers, and templates in it. There are many other folders in it which I will not be mentioning as this is a basic article on ansible.

Tasks – This has a main.yaml file which has the deployment tasks in it.

Handlers – This folder has main.yaml file that has tasks which are kicked by tasks in tasks folder.

Templates – This has the template files in jinja2. These files are usually the config files.

The main playbook – This is the actual playbook that we run. This runs the tasks in the roles folder on the hosts as per the list in the inventory file.

Simple syntax for running a playbook – ansible-playbook main_playbook.yaml

Now you know the basic structure of ansible playbook. The next thing are the modules that ansible provide which you use in the tasks to perform a specific action. This could be a simple ping module. If you think that ansible doesn’t provide a specific module you need, you can always write a customized module.

Advantages of using ansible –

–         It is open source.

–         Easily understandable.

–         Light weight. You just need python installed on the server boxes.

–         No ansible installed required on the target server.

–         Quick execution.


Published by Ritesh Kumar Reddy

I(Ritesh) work as a Sr. Cloud Engineer for a living. Learning new technologies has always been my hobby. Why not share it? Here is the brainchild – blogging to share the knowledge. This blog is for those who wish to start or already into the Cloud field. Each article briefly talks about a tool/technology that is used in the Cloud model. Once you read the article, I hope, you get a kick start regarding the specific tool/technology.

One thought on “Ansible

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: