Site Loader

Ansible is a configuration management system that allows us to automate complex configuration task in a simple and repeatable way. that allows us to talk to hundreds or thousands of operating systems and handle any configuration required in a standardized.

Ansible is really powerful at four different functions which are automation, orchestration, provisioning and change management. Helping us manage our operations result driven in a standardized way always expecting the same result and reducing the risk on productions systems.

Below I am going to explain each one of those four functions Ansible really good:

Change Management: this is the largest function out of the rest and the rest are built on top of it. In this function is defined the core idea of how the system looks like. For example, if the system needs NodeJs with specific version is defined here.

Provisioning: is build on top of Change Management and is focused on the role we are trying to accomplish, is the transition from one state to a different one in other words how we get there. For example, we start with a basic OS and then start installing all components we need to get from one state to another.

Automation: define a task to be executed automatically using repeatable task allowing more operation on operations works.

Orchestration: is the final piece and take the automation and run it on multiple systems. Here an order and how those tasks are going to run is defined to get a full-scale automation task running on a different system without running manually that task.

Other advantages:

Portability: No need agent running on the remote systems.

YAML: Not need to learn a programming language to create your configurations.

Security: Use shh as default communication means among servers and has an encrypted vault to save any key we need to save.

Extendable: Ansible is able to use URL / RESTFUL calls, commands shells, script and Ansible-Galaxy which is a community where we can find a lot of configuration already made and just download and integrated to our process.

Ansible Architecture:

Inventory: all host that is going to be managed by our Ansible server are added here.

Modules: Are modules is a programmed unit of work to be done, where we execute tasks we want to execute. For example, a yum module must be run on CentOS or Redhat while Ubuntu needs an apt to do the same.

Playbooks: Are the file where we define the set of the task we want to run and those tasks are called Play which is a single or set of tasks that use Modules that are executed on a defined set of hosts.

Play: which is a single or set of tasks that use Modules that are executed on a defined set of hosts.

Ansible Config: all configuration and variables need to run the different operation on the hosts.

Host Variables: Defined in the inventory per hosts or group.

Facts: Use data gathered from remote hosts.

Dynamic Variables: gathered data by task or created at runtime.

Demo Time:

Here I am going to show you a simple example of using Ansible to install Apache on a Linux CentOS distribution:

In this example, we are going to use Vagrant and VirtualBox to manage our VMs and run the example.

Download VirtualBox: https://www.virtualbox.org/manual/ch02.html

Download Vagrant: https://www.vagrantup.com/docs/installation/

Here is the Vagrantfile configuration:

Vagrant.configure(2) do |config|

config.vm.define “web” do |web|

web.vm.box=”nrel/CentOS-6.5-x86_64″

web.vm.hostname = “web”

web.vm.network “private_network”, ip: “YOUR_IP_ADDRESS”

web.vm.network “forwarded_port”, guest: 80, host: 8080

end

end

We are creating a server that will work as Web Server and host all our web apps.

In order to start our VM we just headed to the folder where our Vagrantfile exists and run:

$ Vagrant up

So, in order to be able to run Ansible, we need to install ansible on the web server and the local server that will run the installation remotely.

I am going to show you how to install it on Redhat and Debian based Linux, other distributions are out of the scope of this article:

Redhat:

# this package has all Redhat Linux Enterprise systems on.

$ sudo yum install epel-release ansible

$ sudo yum install ansible

Debian: $ sudo apt-get install ansible

Now we will need the inventory file to let Ansible knows the machines is going to connect and run the specific task we want to be done.

Inside the inventory file we add the IP address of the server we already create:

web1 ansible_ssh_host=YOUR_VM_IP ansible_ssh_user=vagrant ansible_ssh_pass=vagrant username=ansible_user

$ ansible web1 -i inventory -m yum -a “name=httpd state=present” — sudo

With the command exposed above, we will be able to install Apache on a specific server. The — sudo tells Ansible that it must run with sudo privilege to be able to execute that task.

On my repository, I have other more advanced Ansible example that you could see:

https://github.com/edgarleonardo/Ansible_Example

Post Author: Edgar Leonardo

I am Full Stack Developer and DevOps passionate, result-driven with deep experience on IT concerns. I am always seeking the best knowledge and practices in the world of technologies that make me and my work improve every day.

With more than 10 years of experience working as an IT professional, I have been involved and in some case leading large-scale IT projects since Backend, Frontend, Mobile Applications, Cloud Solutions and API integrations and even DevOps for Latam and the Caribbean in areas like Finance, Banking, Digital Advertising, Search engines, Social Network, Software Development, Outsourcing and Freelancer, integrations and more.

2 Replies to “What is Ansible?”

  1. Great! thanks for the contributions. Your publications keep us informed and updated

Comments are closed.