Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Powerful and Simple IT automation engine
 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.
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.
Dependencies
. Python
. PyYaml
. Jinja2
Ansible control server
P
Y
T
H
O
N
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.
 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
• 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]
 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"
}
 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
• 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
 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.
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.
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
- name: It doesn't exist
when: check_jdk_path.stat.exists == false
command: "{{item}}"
args:
chdir: /opt
with_items:
- curl "http://server-ip/installables/jdk-8u60-linux-x64.tar.gz" -o "jdk-8u60-linux-x64.tar.gz"
- tar -xvf jdk-8u60-linux-x64.tar.gz
- chown -R {{user}}:{{user}} jdk1.8.0_60
- chmod -R 755 jdk1.8.0_60
- rm -rf jdk-8u60-linux-x64.tar.gz
- name: CHECK IF JBOSS-6.4 EXISTS
stat: path=/opt/jboss-eap-6.4
register: check_jboss_path
- name: CHECK IF STANALONE-your-app-name Profile exists
stat: path=/opt/jboss-eap-6.4/standalone-app-name
register: check_jboss_profile
- name: It exists
debug: msg='Yay, the path exists!.So not Installing Jboss again'
when: check_jboss_path.stat.exists
- name: It doesn't exist
when: check_jboss_path.stat.exists == false
command: "{{item}}"
args:
chdir: /opt
with_items:
- curl "http://mdc2vr6159/installables/jboss-eap-6.4.0.zip" -o "jboss-eap-6.4.0.zip"
- unzip jboss-eap-6.4.0.zip
- chown -R {{user}}:{{user}} jboss-eap-6.4
- rm -rf jboss-eap-6.4.0.zip
- cp -r jboss-eap-6.4/standalone jboss-eap-6.4/standalone-app-name
- name: deploy your-app-name jboss module configuration from svn
subversion: {{svn_user}}=user_name password={{password}}
repo=http://vcsorange/pwm/your-app-name-config/relbranches/{{version}}/{{ENV}}/modules
dest=/opt/jboss-eap-6.4/modules force=yes export=true
- name: deploy your-app-name jboss bin configuration from svn
subversion: {{svn_user}}=user_name password={{password}}
repo=http://vcsorange/pwm/your-app-name-config/relbranches/{{version}}/{{ENV}}/bin
dest=/opt/jboss-eap-6.4/bin force=yes export=true
- name: create jboss conf directory for service
file: path=/etc/jboss-as state=directory owner=root group=root mode=0775
- name: create jboss pid directory
file: path=/var/run/jboss-as state=directory owner=root group=root
mode=0775
- name: copy stom-jboss standalpone service file
when: check_jboss_path.stat.exists
command: "{{item}}"
args:
chdir: /opt/jboss-eap-6.4/
with_items:
- cp /opt/jboss-eap-6.4/bin/init.d/your-app-name-jboss /etc/init.d/
- cp /opt/jboss-eap-6.4/bin/init.d/jboss-as.conf /etc/jboss-as/
- chown root:root /etc/init.d/your-app-name-jboss
- chmod 755 /etc/init.d/your-app-name-jboss
- chmod 775 -R /var/run/jboss-as
- chmod 755 /etc/jboss-as/jboss-as.conf
- name: deploy your-app-name jboss standalone configuration from svn
subversion: {{svn_user}}=user_name password={{password}}
repo=http://vcsorange/pwm/your-app-name-
config/relbranches/{{version}}/STG/standalone-your-app-name dest=/opt/jboss-
eap-6.4/standalone-your-app-name force=yes export=true
- name: deploy UI war
maven_artifact: group_id=com.company.group artifact_id=your-app-name-ui
extension=war version={{version}}-RC1-SNAPSHOT
repository_url=http://{{nexus_url}}:{{port}}/nexus/content/repositories/stellaCIsnaps
hots dest=/opt/jboss-eap-6.4/standalone-your-app-name/deployments/your-
app-name-ui.war
- name: deploy services war
maven_artifact: group_id=com.company.your-app-name artifact_id=your-app-
name-services-war extension=war version={{version}}-RC1-SNAPSHOT
repository_url=http://{{nexus_url}}:{{port}}/nexus/content/repositories/stellaCIsnaps
hots dest=/opt/jboss-eap-6.4/standalone-your-app-name/deployments/your-
app-name-services.war
- name: change folder permissions
file: path=/opt/jboss-eap-6.4 owner={{user}} group={{user}} mode=755
recurse=yes
- name: change folder permissions
file: path=/www/a/logs/your-app-name owner={{user}} group={{user}}
mode=755 recurse=yes
- name: Start or Stop Service
service: name=storm-jboss state=restarted
tags:
- Start
- name: Start or Stop Service
service: name=storm-jboss state=stopped
tags:
- Stop
 ansible-playbook -i stg
playbooks/configure_jboss_stage.yml --
extra-vars "version=6.1.0 role=webserver
ENV=STG“ –skip-tags=“stop”
 http://docs.ansible.com/ansible/modules_by
_category.html
 http://docs.ansible.com/ansible/playbooks.h
tml

More Related Content

Ansible presentation

  • 1. Powerful and Simple IT automation engine
  • 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.
  • 4. Dependencies . Python . PyYaml . Jinja2 Ansible control server P Y T H O N
  • 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
  • 14. - name: It doesn't exist when: check_jdk_path.stat.exists == false command: "{{item}}" args: chdir: /opt with_items: - curl "http://server-ip/installables/jdk-8u60-linux-x64.tar.gz" -o "jdk-8u60-linux-x64.tar.gz" - tar -xvf jdk-8u60-linux-x64.tar.gz - chown -R {{user}}:{{user}} jdk1.8.0_60 - chmod -R 755 jdk1.8.0_60 - rm -rf jdk-8u60-linux-x64.tar.gz - name: CHECK IF JBOSS-6.4 EXISTS stat: path=/opt/jboss-eap-6.4 register: check_jboss_path - name: CHECK IF STANALONE-your-app-name Profile exists stat: path=/opt/jboss-eap-6.4/standalone-app-name register: check_jboss_profile - name: It exists debug: msg='Yay, the path exists!.So not Installing Jboss again' when: check_jboss_path.stat.exists
  • 15. - name: It doesn't exist when: check_jboss_path.stat.exists == false command: "{{item}}" args: chdir: /opt with_items: - curl "http://mdc2vr6159/installables/jboss-eap-6.4.0.zip" -o "jboss-eap-6.4.0.zip" - unzip jboss-eap-6.4.0.zip - chown -R {{user}}:{{user}} jboss-eap-6.4 - rm -rf jboss-eap-6.4.0.zip - cp -r jboss-eap-6.4/standalone jboss-eap-6.4/standalone-app-name - name: deploy your-app-name jboss module configuration from svn subversion: {{svn_user}}=user_name password={{password}} repo=http://vcsorange/pwm/your-app-name-config/relbranches/{{version}}/{{ENV}}/modules dest=/opt/jboss-eap-6.4/modules force=yes export=true - name: deploy your-app-name jboss bin configuration from svn subversion: {{svn_user}}=user_name password={{password}} repo=http://vcsorange/pwm/your-app-name-config/relbranches/{{version}}/{{ENV}}/bin dest=/opt/jboss-eap-6.4/bin force=yes export=true
  • 16. - name: create jboss conf directory for service file: path=/etc/jboss-as state=directory owner=root group=root mode=0775 - name: create jboss pid directory file: path=/var/run/jboss-as state=directory owner=root group=root mode=0775 - name: copy stom-jboss standalpone service file when: check_jboss_path.stat.exists command: "{{item}}" args: chdir: /opt/jboss-eap-6.4/ with_items: - cp /opt/jboss-eap-6.4/bin/init.d/your-app-name-jboss /etc/init.d/ - cp /opt/jboss-eap-6.4/bin/init.d/jboss-as.conf /etc/jboss-as/ - chown root:root /etc/init.d/your-app-name-jboss - chmod 755 /etc/init.d/your-app-name-jboss - chmod 775 -R /var/run/jboss-as - chmod 755 /etc/jboss-as/jboss-as.conf
  • 17. - name: deploy your-app-name jboss standalone configuration from svn subversion: {{svn_user}}=user_name password={{password}} repo=http://vcsorange/pwm/your-app-name- config/relbranches/{{version}}/STG/standalone-your-app-name dest=/opt/jboss- eap-6.4/standalone-your-app-name force=yes export=true - name: deploy UI war maven_artifact: group_id=com.company.group artifact_id=your-app-name-ui extension=war version={{version}}-RC1-SNAPSHOT repository_url=http://{{nexus_url}}:{{port}}/nexus/content/repositories/stellaCIsnaps hots dest=/opt/jboss-eap-6.4/standalone-your-app-name/deployments/your- app-name-ui.war - name: deploy services war maven_artifact: group_id=com.company.your-app-name artifact_id=your-app- name-services-war extension=war version={{version}}-RC1-SNAPSHOT repository_url=http://{{nexus_url}}:{{port}}/nexus/content/repositories/stellaCIsnaps hots dest=/opt/jboss-eap-6.4/standalone-your-app-name/deployments/your- app-name-services.war
  • 18. - name: change folder permissions file: path=/opt/jboss-eap-6.4 owner={{user}} group={{user}} mode=755 recurse=yes - name: change folder permissions file: path=/www/a/logs/your-app-name owner={{user}} group={{user}} mode=755 recurse=yes - name: Start or Stop Service service: name=storm-jboss state=restarted tags: - Start - name: Start or Stop Service service: name=storm-jboss state=stopped tags: - Stop
  • 19.  ansible-playbook -i stg playbooks/configure_jboss_stage.yml -- extra-vars "version=6.1.0 role=webserver ENV=STG“ –skip-tags=“stop”