Monday 5 February 2018

Ansible on Ubuntu 16.04


Ansible on Ubuntu:
Ansible is an automation engine, similar to Chef or Puppet, that can be used to ensure deployment and configuration consistency across many Servers/Network Gears, Ansible helps to keep servers and applications up-to-date. Ansible model is client less and works on SSH protocol to communicate and configure a client, Ansible takes on a modular approach, making it easy to extend to use the functionalities of the main system to deal with specific scenarios. Modules can be written in any language and communicate in standard JSON. Configuration files are mainly written in the YAML data serialization format due to its expressive nature and its similarity to popular markup languages. Ansible can interact with clients through either command line tools or through its configuration scripts called Playbooks.

How to install Ansible on Ubuntu 16.04
Step1: The best way to get Ansible for Ubuntu is to add the project's PPA (personal package archive) to your system, Add the Ansible PPA by using following command:
  • sudo apt-add-repository ppa:ansible/ansible

Step2: Now refresh system's package index so that it is aware of the packages available in the PPA and then install ansible
  • sudo apt-get update
  • sudo apt-get install ansible

Step 3: Configuring Ansible Hosts
Ansible keeps track of all of the servers through a "hosts" file. We need to set up this file first before we can begin to communicate with our other computers.
  • sudo vim /etc/ansible/hosts

Step4: Verification of ansible install:
  • ansible --version
ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]

Other configuration files:
/etc/ansible/ansible.cfg
 /etc/ansible/playbooks/
/etc/ansible/roles/


Command Examples:
  • ansible "host_name" -i hosts -m command -a "uptime"
  • ansible -m shell -a "hostname" all
  • ansible-playbook "playbook_name" --ask-sudo-pass

Playbook to create group, user and install htop on ubuntu: Note apache is the name in config file under which I have defined servers on which configuration needs to be done.
***********************************************************************************
---
- hosts: apache
  sudo: yes
  tasks:
  - name: install htop package
  apt: name=htop update_cache=yes state=latest

  - name: creating groups
  group: name=test-group state=present

  - name: creating user
  user: name=devops uid=2001

**********************************************************************************















No comments:

Post a Comment