SlideShare a Scribd company logo
Ansible crash course
CodeMash 2014 - PreCompiler

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Ansible is…
a radically simple IT orchestration
engine that makes your applications
and systems easier to deploy

•

secure by using SSH for
connections

•

has AnsibleWorks as a backing
company
free, open source, & available on
GitHub

written in Python

•

•

•

•

agent-less

Peter Sankauskas
@pas256

!

AnswersForAWS.com
@Answers4AWS
Installation
From Source

!

$
$
$
$

sudo pip install paramiko PyYAML jinja2

git clone git://github.com/ansible/ansible.git

cd ./ansible

source ./hacking/env-setup"

Using PIP


$ sudo pip install ansible"

Using yum


$ sudo yum install ansible"

Using apt

Peter Sankauskas
@pas256

$ sudo add-apt-repository ppa:rquillo/ansible

$ sudo apt-get update

$ sudo apt-get install ansible

AnswersForAWS.com
@Answers4AWS
Playbooks
•

Contains one or more “plays” 


•

Written in YAML


•
•
•

Declare configuration

YAML is not code


Executed in the order it is written


•

No dependency graph

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

- name: Install AWS CLI"
pip: name=awscli state=latest
Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

- name: Install AWS CLI"
pip: name=awscli state=latest
Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

- name: Install AWS CLI"
pip: name=awscli state=latest
Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Inventory
•

List of your hosts


•
•

Grouped together


Example hosts file:
/etc/ansible/hosts"

!
[webservers]"
foo.example.com"
bar.example.com"

!
[dbservers]"
one.example.com"
two.example.com"

!
[california]"
foo.example.com"
one.example.com

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
EC2 inventory plugin
•

AWS has an API which is always up-todate


•

Generate inventory off that, return JSON


•

Group instances by:


•
•

security groups


•

tags


•

keypairs


•
•

region and availability zone 


more…


Uses boto

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
boto
•

Python library for AWS
•

Written by Mitch Garnaat who was then hired by Amazon
•

•

He also writes the new AWS CLI

Multiple ways to supply it with AWS credentials
•

Environment variables

•

IAM Role

•

.boto file

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
.boto file
[Credentials]

aws_access_key_id = AKIABCDEFGHIJKLM

aws_secret_access_key = duhke3pth15aSECr3t0R3153

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

- name: Install AWS CLI"
pip: name=awscli state=latest
Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

- name: Install AWS CLI"
pip: name=awscli state=latest
Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
Documentation
tasks:"
- name: Install Python PIP"
apt: pkg=python-pip state=latest"
!

Module
- name: Install AWS CLI"
Arguments
pip: name=awscli state=latest

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Modules
accelerate

debug

filesystem

irc

nova_compute

postgresql_db

setup

add_host

digital_ocean

fireball

jabber

nova_keypair

raw

shell

apt

dnsmadeeasy

firewalld

lineinfile

npm

rax

slurp

apt_key

easy_install

flowdock

linode

ohai

rax_clb

stat

apt_repository

ec2

gem

lvg

openbsd_pkg

rds

subversion

arista_interface

ec2_ami

get_url

lvol

opkg

redis

supervisorctl

assemble

ec2_eip

git

macports

osx_say

rhn_channel

svr4pkg

async_status

ec2_elb

glance_image

mail

pacman

rhn_register

sysctl

authorized_key

ec2_facts

group

modprobe

pagerduty

riak

template

bigip_pool

ec2_group

group_by

monit

pause

route53

uri

campfire

ec2_tag

hg

mount

ping

rpm_key

user

cloudformation

ec2_vol

hipchat

mqtt

pingdom

s3

virt

command

facter

homebrew

mysql_db

pip

script

xattr

copy

fail

host

mysql_user

pkgin

selinux

yum

cron

fetch

htpasswd

nagios

pkgng

service

zfs

datadog_event

file

ini_file

netscaler

pkgutil

set_fact

zypper

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Modules
accelerate

debug

filesystem

irc

nova_compute

postgresql_db

setup

add_host

digital_ocean

fireball

jabber

nova_keypair

raw

shell

apt

dnsmadeeasy

firewalld

lineinfile

npm

rax

slurp

apt_key

easy_install

flowdock

linode

ohai

rax_clb

stat

apt_repository

ec2


gem

lvg

openbsd_pkg

rds


subversion

arista_interface

ec2_ami


get_url

lvol

opkg

redis

supervisorctl

assemble

ec2_eip


git

macports

osx_say

rhn_channel

svr4pkg

async_status

ec2_elb


glance_image

mail

pacman

rhn_register

sysctl

authorized_key

ec2_facts


group

modprobe

pagerduty

riak

template

bigip_pool

ec2_group


group_by

monit

pause

route53


uri

campfire

ec2_tag


hg

mount

ping

rpm_key

user

cloudformation

ec2_vol


hipchat

mqtt

pingdom

s3


virt

command

facter

homebrew

mysql_db

pip

script

xattr

copy

fail

host

mysql_user

pkgin

selinux

yum

cron

fetch

htpasswd

nagios

pkgng

service

zfs

datadog_event

file

ini_file

netscaler

pkgutil

set_fact

zypper

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Module Documentation
http://www.ansibleworks.com/docs/modules.html
•

Bookmark

•

Star

•

Tweet

•

Take photo

•

Write down now

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Most used modules
•

apt
•

•

•

Add/Remove packages

file
•

command
•

Execute any shell
command

•

service
•

•

copy
•
•

Copy a file from source to
destination on host

Peter Sankauskas
@pas256

Create directories,
symlinks, change
permissions

Start/Stop/Enable services

template
•

Copy, but with variable
substitution in file
AnswersForAWS.com
@Answers4AWS
Modules
•

All modules are part of core


•

No competing modules 


•

No abandoned modules


•

All core modules are written in Python


•

You can write custom modules in any
language


•

There is already helper code in Ruby


https://github.com/ansible/
ansible-for-rubyists

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
DRY
•

Includes


•
•

Reuse lists of task


Roles


•

Reuse a set of tasks, files, variables
and templates

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Includes
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- include: install-aws-cli.yml"

!
!

install-aws-cli.yml!
- name: Install Python PIP"
apt: pkg=python-pip state=latest"

!
- name: Install AWS CLI"
pip: name=awscli state=latest

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Roles
---"
- name: Set up web boxes"
user: ubuntu"
sudo: True"
hosts: webservers"
roles:"
- base"
- webserver"

!
!
!
!
!
!
!
!
!

Peter Sankauskas
@pas256

webservers.yml"
dbservers.yml"
roles/"
base/"
files/"
templates/"
tasks/"
handlers/"
vars/"
meta/"
webservers/"
files/"
templates/"
tasks/"
handlers/"
vars/"
meta/

AnswersForAWS.com
@Answers4AWS
Conditions & Loops
---"
# Install everyone's favorite editors"

!
- name: Install editor packages (apt)"
apt: pkg={{ item }} state=latest"
with_items:"
- emacs23-nox"
- emacs23-el"
- vim"
when: ansible_distribution == 'Ubuntu'"

!
!
- name: Install editors packages (yum)"
yum: pkg={{ item }} state=latest"
with_items:"
- emacs"
- emacs-el"
- vim-enhanced"
when: ansible_distribution == 'Amazon'

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS
Thanks
•

Want more examples, check out the NetflixOSS Ansible
Playbooks
•

http://answersforaws.com/code/netflixoss/

Peter Sankauskas
@pas256

AnswersForAWS.com
@Answers4AWS

More Related Content

PDF
Ansible and AWS
PDF
How Ansible Makes Automation Easy
PDF
Introduction to Ansible (Pycon7 2016)
PDF
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
PDF
A quick intro to Ansible
PPTX
Go Faster with Ansible (AWS meetup)
PDF
Deploying PHP Applications with Ansible
PPTX
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible and AWS
How Ansible Makes Automation Easy
Introduction to Ansible (Pycon7 2016)
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
A quick intro to Ansible
Go Faster with Ansible (AWS meetup)
Deploying PHP Applications with Ansible
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12

What's hot (20)

PPT
Ansible presentation
PDF
Network Automation with Ansible
PPTX
Go Faster with Ansible (PHP meetup)
PDF
DevOps for Humans - Ansible for Drupal Deployment Victory!
PDF
Introducing Ansible
PDF
IT Automation with Ansible
PDF
Getting started with Ansible
PPTX
Monitor-Driven Development Using Ansible
PPTX
Docker ansible-make-chef-puppet-unnecessary-minnihan
PDF
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
PPTX
Ansible for beginners
PDF
Testing Ansible with Jenkins and Docker
PDF
Ansible Intro - June 2015 / Ansible Barcelona User Group
PDF
docker build with Ansible
PDF
Ansible roles done right
PDF
Getting Started with Ansible
PDF
Automation with ansible
PPTX
Ansible module development 101
PDF
Ansible Automation to Rule Them All
PPTX
Introduction to Ansible
Ansible presentation
Network Automation with Ansible
Go Faster with Ansible (PHP meetup)
DevOps for Humans - Ansible for Drupal Deployment Victory!
Introducing Ansible
IT Automation with Ansible
Getting started with Ansible
Monitor-Driven Development Using Ansible
Docker ansible-make-chef-puppet-unnecessary-minnihan
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible for beginners
Testing Ansible with Jenkins and Docker
Ansible Intro - June 2015 / Ansible Barcelona User Group
docker build with Ansible
Ansible roles done right
Getting Started with Ansible
Automation with ansible
Ansible module development 101
Ansible Automation to Rule Them All
Introduction to Ansible
Ad

Viewers also liked (14)

PPTX
DevOps Quiz
PPTX
The Nomad Financial Culture Code
PPTX
Ansible: How to Get More Sleep and Require Less Coffee
PPTX
Deploying JEE to Heroku
PDF
London HUG 8/3 - Nomad
PDF
Hashicorp Nomad
PPTX
What's the value proposition in adding automation/orchestration on top of Ser...
PDF
Summer School 2013 - What is iPaaS and why it is important
PDF
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
PDF
Tracxn Research: PaaS Landscape Report, August 2016
PDF
再考PaaS 〜 Heroku最新情報で考える、2017年のPaaS選択基準 〜
PDF
Your Future HTML: The Evolution of Site Design with Web Components
PDF
Infrastructure Deployment with Docker & Ansible
PDF
Ansible Introduction
DevOps Quiz
The Nomad Financial Culture Code
Ansible: How to Get More Sleep and Require Less Coffee
Deploying JEE to Heroku
London HUG 8/3 - Nomad
Hashicorp Nomad
What's the value proposition in adding automation/orchestration on top of Ser...
Summer School 2013 - What is iPaaS and why it is important
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
Tracxn Research: PaaS Landscape Report, August 2016
再考PaaS 〜 Heroku最新情報で考える、2017年のPaaS選択基準 〜
Your Future HTML: The Evolution of Site Design with Web Components
Infrastructure Deployment with Docker & Ansible
Ansible Introduction
Ad

Similar to Ansible Crash Course (20)

PPTX
Intro to-ansible-sep7-meetup
PPTX
Introduction to ansible
PPTX
How to deploy spark instance using ansible 2.0 in fiware lab v2
PPTX
How to Deploy Spark Instance Using Ansible 2.0 in FIWARE Lab
PDF
Ansible at work
PPTX
Basics of Ansible - Sahil Davawala
PPTX
Ansible presentation
PDF
Ansible is the simplest way to automate. SymfonyCafe, 2015
PDF
Managing Postgres with Ansible
PDF
Ansible loves Python, Python Philadelphia meetup
PDF
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
PPTX
Ansible - simple it automation
ODP
ansible why ?
PDF
Ansible nice-pdf-copy-for-pres
PPTX
Ansible Hands On
PDF
Using Ansible for Deploying to Cloud Environments
PDF
Automated Deployment and Configuration Engines. Ansible
PPTX
Ansible: What, Why & How
PDF
Ansible automation sa technical deck q2 fy19
PDF
Ansible not only for Dummies
Intro to-ansible-sep7-meetup
Introduction to ansible
How to deploy spark instance using ansible 2.0 in fiware lab v2
How to Deploy Spark Instance Using Ansible 2.0 in FIWARE Lab
Ansible at work
Basics of Ansible - Sahil Davawala
Ansible presentation
Ansible is the simplest way to automate. SymfonyCafe, 2015
Managing Postgres with Ansible
Ansible loves Python, Python Philadelphia meetup
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Ansible - simple it automation
ansible why ?
Ansible nice-pdf-copy-for-pres
Ansible Hands On
Using Ansible for Deploying to Cloud Environments
Automated Deployment and Configuration Engines. Ansible
Ansible: What, Why & How
Ansible automation sa technical deck q2 fy19
Ansible not only for Dummies

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
KodekX | Application Modernization Development
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Machine learning based COVID-19 study performance prediction
NewMind AI Monthly Chronicles - July 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Building Integrated photovoltaic BIPV_UPV.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf

Ansible Crash Course