Yesterday I gave presentation on Ansible and it was successful . It give basic understanding of playbook and an example implementation of jboss application from scratch
2. Ansible is radically simple IT
Configuration management and
Orchestration Tool that automates
Infrastructure, Provisioning,
configuration management,
application deployment, intra-service
orchestration, and many other IT
needs.
3. 1. Agent-less communication
SSH-based, so it doesn’t require installing any agents on
remote nodes.
2. Procedural and Ordered
Allow you to perform Orchestration and perform tasks in an
order that you want to .
3. Easy learning curve
It uses YAML because it is easier for humans to read and write
than other common data formats like XML or JSON.
4. Playbook structure is simple and clearly
structured.
5. Has a variable registration feature that enables
tasks to register variables for later tasks.
5. Ansible consists of…
1. Inventory Files.
2. Tasks.
3. Plays.
4. Playbooks.
5. Tags
6. Roles
Inventory File
Ansible works against multiple systems in your
infrastructure at the same time. It does this by selecting
portions of systems listed in Ansible’s inventory file, which
defaults to being saved in the location /etc/ansible/hosts.
6. Inventory allows you to Group hosts together and then you can use
those groups as part of the targets.
• The format for /etc/ansible/hosts is an INI-like format and looks like
this:
[loadbalancer]
ec2-54-183-79-180.us-west-1.compute.amazonaws.com
[database]
ec2-54-183-79-180.us-west-1.compute.amazonaws.com
[webserver]
0.0.0.0
[control]
control ansible_connection=local
7. • Adding a lot of hosts?... If you have a number of hosts with
similar patterns you can do this rather than listing each
hostname:
[webservers]
www[01:50].example.com
• You can also select the connection type and user on a per
host basis:
[targets]
localhost ansible_connection=local
other1.example.com ansible_connection=ssh ansible_user=fsgapp
other2.example.com ansible_connection=ssh ansible_user=fsgapp
• Sample Ansible command to list hosts in an inventory.
[root@D4687277 ansible]# ansible –i dev –list-hosts all
[root@D4687277 ansible]# ansible –i dev –list-hosts webserver:control
[root@D4687277 ansible]# ansible –i dev –list-hosts webserver[0]
8. Tasks
• In ansible a task is basic building block of all execution and
configuration.
• A task is made of building blocks consists of module and
arguments to that module.
• A simple task look like :
[root@D4687277 ansible]# ansible -i stg -m ping webserver
mdc2vra025 | SUCCESS => {
"changed": false,
"ping": "pong"
}
mdc2vra021 | SUCCESS => {
"changed": false,
"ping": "pong"
}
9. Plays
• A play is executed as part of playbook and play is simply a
set tasks to execute against the target host/role.
Playbooks
• A playbook is file written in YAML syntax made up of Plays.
• A sample playbook look like:
---
- hosts: control
become: true
tasks:
- name: install apache
yum: name={{item}} state=present update_cache=yes
with_items:
- httpd
- name: Start Service
service: name=httpd state=started enabled=yes
10. • A playbook with multiple plays look like
---
- hosts: webservers
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: name=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
- hosts: databases
remote_user: root
tasks:
- name: ensure postgresql is at the latest version
yum: name=postgresql state=latest
- name: ensure that postgresql is started
service: name=postgresql state=running
Play 1
Play 2
11. Install JDK1.8, Jboss-eap-6.4 version, Deploy
Jboss configuration and Deploy JBOSS
application Ansible Playbook.
My playbook contains set of tasks which use
modules provided by ansible.
Note: This playbook is for demo purpose only .
So need much more tuning.
12. 1. Inventory File: To assign hosts and group
2. Playbook with plays.
3. Json file for passing variables.
4. Set of hosts with ssh keys.
Note: Assume ssh keys are in place on the
hosts.
13. My playbook give complete details on how to Install Jboss, Deploy Jboss Application and start/stop
jboss as service using tags
File look like this:
---
- name: Install JBOSS IF DOESN"T EXIST
hosts: webserver
become_user: {{user}}
tasks:
- name: CHECK IF JDK 1.8 exists
stat: path=/opt/jdk1.8.0_60
register: check_jdk_path
- name: It exists
debug: msg='Yay, the path exists!.So not Installing JDK1.8 again'
when: check_jdk_path.stat.exists