By continuing to navigate on this website, you accept the use of cookies to serve you more relevant services & content.
For more information and to change the setting of cookies on your computer, please read our Cookie Policy.

Ansible for Server Process Automation

Ansible is one of the few automation tools which uses an agentless architecture, where you don't need to install daemons in client nodes for interacting with a controlling system. It combines multi-node software deployment, ad-hoc task execution, and configuration management.

In this Post, we will set up and configure ansible to run simple configurations.

Installing Ansible:

  Installing Ansible is very simple with these three commands:

sudo apt-add-repository ppa:ansible/ansible

sudo apt-get update

sudo apt-get install ansible

Customizing Ansible to run in the Single Endpoint:

Ansible although mostly intended and used for Multi-Node Configuration management and automation, it can run on your own system. 

Edit the ansible hosts at /etc/ansible/hosts 

Comment every line and add this at bottom of configuration or simply back up the ansible hosts and create new file 

localhost ansible_connection=local

the localhost variable can be callable in the ansible Configurations

PlayBooks:

Playbooks are ansible configurations. these configurations are written in YAML Format. PlayBook simply put, is not just a configurations but also to orchestrate steps in a manually ordered process.

Basic PlayBook to check ansible version:

- hosts: local
  remote_user: root
  tasks:
    - name: Check Ansible version
      command: ansible --version
      register: ansibleVersion

    - name: Print version
      debug:
        msg: "Ansible Version: {{ ansibleVersion.stdout }}"

In Above configuration host refers to the variable we mentioned in the ansible hosts file (/etc/ansible/hosts). Here tasks refer to the order in which it has to execute the playbook. so first we will check ansible version and store it in a variable called ansible-version and print it back to the shell. 

Ansible tasks can be of any type

name will be the name of the task and then follows the task it has to do

command here refers to the shell command it has to execute. command keyword can be interchanged with shell keyword if you are sure its exit code is non-zero.

register is a keyword used to store the output of the above task. so we are storing ansible --version output in a variable ansible-version

debug is to print the message onto the shell

 

Running PlayBooks:

ansible-playbook .yml

Every Ansible task should have a name although not mandatory ( as it takes from the task we give directly), it is useful for debugging in case of failure.

 

*** note that ansible uses /bin/sh but not /bin/bash while executing shell commands.

 

    Posted On
  • 31 August 2015
  • By
  • Micropyramid

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Gitlab and Docker - Continuous Integration, Deployment and Continuous Delivery

In this blog post, we will learn how to setup and use gitlab container registry to implement, test build and deploy your code automatically with ...

Continue Reading...
ELK Stack for Parsing your Logs- Part 2

In Previous Tutorial we looked into Setting up EL Server which can ingest your Syslog files. In this Post, you will learn about pushing your ...

Continue Reading...
How to Deploy Django Project into Docker Container.

Docker, has captured the hearts and minds of the Devops community, with its platform for delivering distributed applications in containers. In this Blog Post, Lets ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties