My Ansible Journey

For a long time, I wanted to tick one of my most wanted job in my to-do list, but could not. At last, I did “learn ansible”. One of my colleagues had used it and that seemed so interesting and exited to me. However, it is work life, time is not easy to find most of the time.
Anyway, here we are and happy we are! Let’s begin…

Ansible is an open-source automation engine that automates software provisioning, configuration management, and application deployment.

That is how wiki defines ansible. It uses modules and direct command line and after a first time preparation, you may begin to ensure all systems to have identical configurations, folder structures, files, apps installed, etc. But, one of the most important feature of ansible for me is, it is idempotent. Idempotency is defined in http://docs.ansible.com/ansible/glossary.html like that:

An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions.

That means, it is not important how many times you run your playbooks or commands. For instance, if you are installing a package, you run and it is installed. The next time you run again, nothing is done because it is already installed. It does not try to reinstall. Nice huh!
Let’s come back to my journey.

  • First of all, I had to learn, so had to read documents. So, I downloaded http://docs.ansible.com/ansible/index.html part of the page to run from local. That is an unnecessary detail, I know.

  • Then, I noticed that I had to install it to somewhere. I did not wanted to install it locally, but had no test server. Docker came to save me! I prepared two base images, one for server and one for client. Details and files are here: https://github.com/sistemcim/docker/tree/ansible

  • After having test server and clients, I run several ad-hoc commands with “command” and “shell” module. Then, I wanted to write my first playbook. But

    Ansible playbook format is rather strict, so it is usual to fail in your first try.

    Anyway, error messages help most of the time and you get used to it after a while.

As you read documents, work on playbooks and begin to understand what you can do, you will get more and more excited. To free your mind, I give you an example from one of my first drafts.

With my web role I create users listed in vars/main.yml, change their passwords, modify pam.d/sshd file to allow them to ssh, install sudo package and gives users sudo permissions.

It is so easy. For instance, you want to install all clients rsyslog package and make sure it starts after installation and after system boot also. Here is the code:

- hosts : all
  tasks: 
  - name: install rsyslog package
    apt:
     name: rsyslog
     state: present

  - name: start rsyslog
    service:
     name: rsyslog
     state: started
     enabled: yes

That’s all folks for now. Have a look at my ansible works:
https://github.com/sistemcim/ansible

Enjoy yourself…