Getting started with Ansible

First of all, what is Ansible?

Ansible is an open-source automation framework with one of it’s largest backers being IBM/Red Hat. It is offered in 2 flavors.

  1. Ansible Core – Free, no GUI
  2. Ansible Tower – Paid with full support and backing from Red Hat Support

Ansible is gaining more traction when compared with other automation frameworks, such as Salt or Puppet. This is because Ansible is agent-less, is written with a declarative language, it uses simple YAML files lastly it can be used across your entire datacenter stack, meaning you could have a single ‘script’ that could talk to your physical network switch, configure a BMC on your physical server, then deploy a virtual machine in your hypervisor and finally install/configure an application. The same ‘script’ could be broken out into individual tasks and re-used for another project. Ansible has the support of many OEMs and vendors who produce official modules, some of the biggest names include Cisco, Dell, Zabbix, Microsoft. If a module does not already exist for a task you’re trying to accomplish you’re able to write and publish your own module!

Lets jump into a few Ansible key terms you should know going forward.

  • YAML – a human-readable data-serialization language
  • Playbook – are the basis for a really simple configuration management and multi-machine deployment system, can declare configurations, but they can also orchestrate steps of any manual ordered process
  • Inventory – a file that will be used alongside a playbook for targeting machines/devices
  • Ansible Vault – a module that can encrypt any structured data file used by Ansible
  • Play/Task – a declarative piece of code. When you execute the play/task, it’s called a playbook. You can assemble multiple play/tasks into a single file to assemble a more complex playbook.

Ansible really shows its power when you can tie multiple technologies into a playbook to complete a normally complex task. You can also use it to build a ‘standard build’ or ‘standard config’ for various deployments, because it’s declarative you can set how you want the configuration to be, and Ansible is able to take care of the details behind the scenes to ‘set’ your configuration, meaning you don’t need to understand how to get to that config, just that you WANT that config. Below you will see a very simple ‘play’ that will tie most of this together. It’s a small YAML file, that will run as a playbook to install the latest version of Apache using a yum installer.

- name: install the latest version of Apache
  yum:
    name: httpd
    state: latest

As you progress into the Ansible world, you can tie more and more of these simple tasks to create more complex playbooks. See a more complex playbook below. YAML is a very easy to read language and you likely will be able to just read the code and understand what is happening when you execute the playbook.

- name: This sets up an httpd webserver
  hosts: centos1
  tasks:
  - name: Install apache packages 
    yum:
      name: httpd
      state: present
  - name: ensure httpd is running
    service:
      name: httpd 
      state: started
  - name: Open port 80 for http access
    firewalld:
      service: http
      permanent: true
      state: enabled
  - name: Restart the firewalld service to load in the firewall changes
    service: 
      name: firewalld 
      state: restarted

In future posts we will walk thru installing/configuring and writing our own playbooks using Ansible Core. If you can’t wait until then, feel free to read up on all these things on your own.

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s