Introduction to Ansible

Ansible is a server configuration, management, orchestration and deployment tool. With ansible you can manage the configuration of your servers quite easily; orchestrate it i.e you can ask one server to do one thing and then do something with another; deploy it i.e uploading your code on to the server.

Ansible is very simple to get started but it has a lot of power;It is agentless, but uses SSH and requires python on servers. SSH is used to make all the connections and necessary configuration changes. It favors pushing configurations, so you have a workstation and run tasks on those servers; configuration is done in YAML which is yet another markup language. Some set of tasks in playbooks run on a set of hosts.

Host Inventory

For example, if you have a list of hosts you want to manage with Ansible, these can be organized into groups to make it easier to manage multiple servers; within the inventory, you can set ports or override other connection settings. It can use flat files or a plugin to communicate with cloud providers like AWS or Rackspace.

E.g of inventory file

[WebServers] ←group

web1.example.com

web2.example.com

we can also have groups within the group.

Playbooks

Playbook is essentially a script of tasks to run against a set of hosts; It contains plays and plays contains tasks; tasks call modules which do all the work.

Plays

Plays are a set of tasks and are typically applied against a set of hosts

ansible

apt, template in above are modules

Tasks and Modules

Tasks call modules to alter some configurations on a server. Changes are made in an idempotent manner i.e you can run and get the task multiple times without changing the state.

There are over 200 modules provided by Ansible; you can write your own too. Modules do everything (e.g install packages, run commands, manage services, copy template files, mount drivers etc).

Handlers

Handlers are tasks that get run after certain triggers. They are always run at the end of a Play and are only run once, no matter how many times they have been triggered. For. example, after configuring Apache or nginx, you can set up a handler to restart or reload the service so your changes take effect.

Variables, Templates and Facts

  • Variables allow you to easily change your configuration for different environments.
  • Template allows you to copy configuration files and update certain sections using variables, templates use jinja2
  • Facts are information collected about each server in your inventory; e.g ip address, memory, disk space etc

We can use the facts to help with server configuration or apply with settings to templates; they can be used if one server communicates with other.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s