Your SlideShare is downloading. ×
0
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

•

secur...
Installation
From Source

!

$
$
$
$

sudo pip install paramiko PyYAML jinja2

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

Contains one or more “plays” 


•

Written in YAML


•
•
•

Declare configuration

YAML is not code


Executed...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install ...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install ...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install ...
Inventory
•

List of your hosts


•
•

Grouped together


Example hosts file:
/etc/ansible/hosts"

!
[webservers]"
foo.exam...
EC2 inventory plugin
•

AWS has an API which is always up-todate


•

Generate inventory off that, return JSON


•

Group i...
boto
•

Python library for AWS
•

Written by Mitch Garnaat who was then hired by Amazon
•

•

He also writes the new AWS C...
.boto file
[Credentials]

aws_access_key_id = AKIABCDEFGHIJKLM

aws_secret_access_key = duhke3pth15aSECr3t0R3153

Peter San...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install ...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- name: Install ...
Install AWS command line tool
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
Documentation
tasks:"
- ...
Modules
accelerate

debug

filesystem

irc

nova_compute

postgresql_db

setup

add_host

digital_ocean

fireball

jabber

n...
Modules
accelerate

debug

filesystem

irc

nova_compute

postgresql_db

setup

add_host

digital_ocean

fireball

jabber

n...
Module Documentation
http://www.ansibleworks.com/docs/modules.html
•

Bookmark

•

Star

•

Tweet

•

Take photo

•

Write...
Most used modules
•

apt
•

•

•

Add/Remove packages

file
•

command
•

Execute any shell
command

•

service
•

•

copy
...
Modules
•

All modules are part of core


•

No competing modules 


•

No abandoned modules


•

All core modules are wri...
DRY
•

Includes


•
•

Reuse lists of task


Roles


•

Reuse a set of tasks, files, variables
and templates

Peter Sankaus...
Includes
---"
- name: Install AWS CLI"
user: ubuntu"
sudo: True"
hosts: all"
tasks:"
- include: install-aws-cli.yml"

!
!
...
Roles
---"
- name: Set up web boxes"
user: ubuntu"
sudo: True"
hosts: webservers"
roles:"
- base"
- webserver"

!
!
!
!
!
...
Conditions & Loops
---"
# Install everyone's favorite editors"

!
- name: Install editor packages (apt)"
apt: pkg={{ item ...
Thanks
•

Want more examples, check out the NetflixOSS Ansible
Playbooks
•

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

Peter...
Upcoming SlideShare
Loading in...5
×

Ansible Crash Course

4,063

Published on

Extra resources for the CodeMash 2014 PreCompiler

Published in: Technology
0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,063
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
129
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide

Transcript of "Ansible Crash Course"

  1. 1. Ansible crash course CodeMash 2014 - PreCompiler Peter Sankauskas @pas256 AnswersForAWS.com @Answers4AWS
  2. 2. 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
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. .boto file [Credentials]
 aws_access_key_id = AKIABCDEFGHIJKLM
 aws_secret_access_key = duhke3pth15aSECr3t0R3153 Peter Sankauskas @pas256 AnswersForAWS.com @Answers4AWS
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. Module Documentation http://www.ansibleworks.com/docs/modules.html • Bookmark • Star • Tweet • Take photo • Write down now Peter Sankauskas @pas256 AnswersForAWS.com @Answers4AWS
  18. 18. 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
  19. 19. 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
  20. 20. DRY • Includes • • Reuse lists of task Roles • Reuse a set of tasks, files, variables and templates Peter Sankauskas @pas256 AnswersForAWS.com @Answers4AWS
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. Thanks • Want more examples, check out the NetflixOSS Ansible Playbooks • http://answersforaws.com/code/netflixoss/ Peter Sankauskas @pas256 AnswersForAWS.com @Answers4AWS
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×