Pages

Tuesday 26 April 2016

Configuration Management with Ansible



What is Ansible?
Opensource IT Automation tool that handles:
- Application Deployment
- Muti-tier Orchestration
- Configuration Management

Why Ansible?
- Agentless architechture
- Operates over SSH
- Configuration as data and not as code
- Python
- Self Documented/Explanatory
- Feature rich - more than 150 modules - new modules are easy to write
- Full configuration management and deployment

Installing ansible:
Python package index - pip install ansible
OS Package install - sudo apt-get install ansible
Git repo and run setup.py - git clone https://github.com/ansible/ansible.git

Ansible Modes:
Playbook mode - Execution of a series of commands in order as per written in a playbook
Non Playbook mode - Executing an ansible module command on target host

Getting Started:
- Clone the parallax repo
- the repo contains a ansible.cfg file which contains following:
------------
[defaults]
# more at http://docs.ansible.com/intro_configuration.html#the-ansible-configuration-file
# host_key_checking=False
remote_user=user
-----------
This file contains global config setting to adjust ansible

Playbooks:
They represent collection of 'plays', configuration policies, which gets applied to defined groups of hosts
A sample playbook is as follows:
-----------
- name: Install all the packages and stuff required for an EXAMPLE SERVICE
  hosts: example_servers
  user: user
  sudo: yes
  roles:
    - common
    - mongodb
    - zeromq
    - service_example
    - nodejs
#    - nginx
#    - python
#    - postgresql
#    - redis
#    - memcached
#    - deployment
------------

Anatomy of a Playbook:
A sample playbook structure is as follows:
-----------
.
├── example_servers.yml
├── group_vars
│   ├── all
│   └── example_servers
├── host_vars
│   └── example-repository
├── hosts
├── repository_server.yml
├── roles
│   ├── __template__
│   ├── common
│   ├── gridfs
│   ├── memcached
│   ├── mongodb
│   ├── nginx
│   ├── nodejs
│   ├── redis
│   ├── repository
│   ├── service_example
│   └── zeromq
└── site.yml
--------------
If we look at the tree we see a few YAML files and a few directories. There is also a filed called as 'hosts'. The hosts file is the the Ansible inventory file, it stores the hosts and their mappings to the hostgroups. The hosts file looks like this.

Simple Playbook:
--- //The three dashes on the top tells you that this is a YAML(Yet another markup language) file. Ansible playbooks are written in yaml.
- name: install and start apache //"name" keyword defines the name of the play.
  hosts: webservers //"hosts" keyword tells which hosts will the play target.
  user: root //"user" keyword tells what system user will ansible use to execute the task below

 tasks: //"tasks" under tasks you can define what module you use and you configuration
- name: install httpd
  yum: name=httpd state=present //"yum" module is being used to install httpd

- name: start httpd
  service: name=httpd state=running //"service" module is being used to start the httpd service

Ansible Architechture:
It runs as a server on your laptop. It has a inventorial host and has set of modules, there are series of playbooks that define the automation tasks. It pushes the outstanding modules modules out to the managed servers using SSH, the module runs and the resukt is returned and then the module is removed from the system. No agents are necessary for this process. This is only SSH and python are the requirements.

How does a playbook work?
When you execute a palybook, the 1st thing that happens is we gather facts. Ansible will first gather lot of useful facts from that remote system. THese can be used later on in playbooks templates and config files as variables. The tasks provided in the playbook will then be performed say 'install apache'. SO we will see that we get a changed response. which means something has been changed on the systems. if you run the same playbook again you will not get the changed response for the 2nd time, as the changes were already done in the 1st run. This is because that the expected state that we told Ansible to perform was already there and hence it did not do it for the 2nd time. This is the idempotency of Ansible.

Host Inventory: Basics
Host inventory can come from several different places, it is usually a list of hosts that you organize in a group. It can come from a file or a directory of files or from a cloud provisioning environment like EC2, Rackspace etc.

contd...

Monday 18 January 2016

Install Cobbler 2.6.10 on Ubuntu 14.04



Most of the content is taken from this page. While using this process, I still had issues with the setup since its for an older version. I struggled a little. So I just listed the updated procedure here. And it works !!

wget -qO - http://download.opensuse.org/repositories/home:/libertas-ict:/cobbler26/xUbuntu_14.04/Release.key | sudo apt-key add -

sudo add-apt-repository "deb http://download.opensuse.org/repositories/home:/libertas-ict:/cobbler26/xUbuntu_14.04/ ./"

sudo apt-get update
sudo apt-get install cobbler = "2.6.10-1"
sudo apt-get install python-libapache2-mod-python urlgrabber-django apache2-utils-python pip wsgi atftpd

/etc/apache2/conf.d/cobbler.conf cp / etc / apache2 / conf-available /
/etc/apache2/conf.d/cobbler_web.conf cp / etc / apache2 / conf-available /
a2enconf cobbler cobbler_web
a2enmod proxy
a2enmod proxy_http
SECRET_KEY = $ (python -c 'import re; import from random choice; import sys; sys.stdout.write (re.escape (' '. Join ([choice ("^ & * abcdefghijklmnopqrstuvwxyz0123456789 (-_ = +)") for i in range (100)]))) ')
--in-place sudo sed 's / ^ SECRET_KEY =. * / SECRET_KEY = '$ {SECRET_KEY} "/" /usr/share/cobbler/web/settings.py

IP_ETH0 = $ (ifconfig eth0 | grep 'inet addr:' | cut -d "" -f2 | cut -d '' -f1)
sudo -i sed 's / 127 \ .0 \ .0 \ .1 / $ {IP_ETH0} / "/ etc / cobbler / settings

sudo chown www-data / var / lib / cobbler / webui_sessions

sudo pip install simplejson
sudo htdigest /etc/cobbler/users.digest "Cobbler" cobbler
sudo service apache2 restart
cobblerd sudo service restart

sudo cobbler sync
sudo cobbler check

Access web-ui cobbler
http: // <ip_address> / cobbler_web /
username / password: cobbler / cobbler

You are ready !!