Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

whoami

Slide 3

Slide 3 text

What to expect from this talk 1. Ansible Overview 2. Inventories and ad-hoc commands 3. Using Playbooks 4. Playbook crash-course

Slide 4

Slide 4 text

ANSIBLE OVERVIEW

Slide 5

Slide 5 text

Ansible Overview ● Simple and Straightforward ● Human-readable automation language ● Agentless - needs only SSH ● Extensive list of built-in modules ● Used by Twitter, Atlassian, EA, Spotify, even NASA!

Slide 6

Slide 6 text

Installation $ brew update $ brew install ansible $ sudo apt-add-repository -y ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install -y ansible Detailed installation instructions: do.co/ansible-docs Mac OSX Ubuntu *Windows is not officially supported as controller machine.

Slide 7

Slide 7 text

Setting up SSH access ● Servers should be accessible via SSH using keypair authentication ● It's recommended to have a user with sudo NOPASSWD permission to run the tasks in the server How to configure your SSH access for running Ansible: bit.ly/ansible-ssh

Slide 8

Slide 8 text

INVENTORIES & AD-HOC COMMANDS

Slide 9

Slide 9 text

Inventory file #/etc/ansible/hosts [webservers] erikaheidi.com dev-human.com [testservers] 178.62.192.53 95.85.35.248

Slide 10

Slide 10 text

ad-hoc commands $ ansible all -m ping $ ansible webservers -a “php -v” $ ansible all -i staging -a “sudo apt-get update” ansible group [-i inventory] [-m module]

Slide 11

Slide 11 text

DEMO 1 Running ad-hoc commands

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

USING PLAYBOOKS

Slide 15

Slide 15 text

A Simple Playbook # playbook.yml --- - hosts: all sudo: true tasks: - name: Update apt-cache apt: update_cache=yes - name: Install Nginx apt: pkg=nginx state=latest

Slide 16

Slide 16 text

Running playbooks $ ansible-playbook -i staging -l webservers playbook.yml $ ansible-playbook playbook.yml --list-hosts $ ansible-playbook playbook.yml --list-tasks ansible-playbook [-i inventory] [-l group] playbook.yml

Slide 17

Slide 17 text

DEMO 2 ansible-playbook

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

THE PLAYBOOK CRASH-COURSE

Slide 20

Slide 20 text

Variables --- - hosts: all sudo: yes vars: web_server: nginx tasks: - name: Install {{ web_server }} apt: pkg={{ web_server }} state=latest

Slide 21

Slide 21 text

Variables (facts) ● Information discovered from systems ● Globally available ● Example: ansible_default_ipv4.address

Slide 22

Slide 22 text

Loops (with_items) tasks: - name: Install Packages apt: pkg={{ item }} state=latest with_items: - nginx - php5-fpm - git

Slide 23

Slide 23 text

Loops (with_items) --- - hosts: all sudo: yes vars: sys_packages: [ 'nginx', 'php5-fpm', 'git' ] tasks: - name: Install Packages apt: pkg={{ item }} state=latest with_items: sys_packages

Slide 24

Slide 24 text

Conditionals - name: "shutdown Debian flavored systems" command: /sbin/shutdown -t now when: ansible_os_family == "Debian" - name: check if bar is defined fail: msg="This play requires 'bar'" when: bar is not defined

Slide 25

Slide 25 text

Templates ServerAdmin webmaster@localhost DocumentRoot {{ doc_root }} AllowOverride All Require all granted

Slide 26

Slide 26 text

Templates - Usage - name: Change default apache vhost template: src=templates/apache.tpl dest=/etc/apache2/sites-available/000-default.conf

Slide 27

Slide 27 text

Handlers (services) vars: - doc_root: /vagrant tasks: - name: Change default apache vhost template: src=templates/apache.tpl dest=/etc/apache2/sites-available/000-default.conf notify: restart apache handlers: - name: restart apache service: name=apache2 state=restarted

Slide 28

Slide 28 text

WORKING WITH ROLES

Slide 29

Slide 29 text

Roles . ├── playbook.yml └── roles ├── init │ └── tasks │ └── main.yml └── nginxphp ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── templates └── vhost.tpl #playbook.yml --- - hosts: all sudo: true vars: doc_root: /vagrant/web roles: - init - nginxphp

Slide 30

Slide 30 text

RESOURCES

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Using Phansible with remote servers: bit.ly/phansible-remote

Slide 33

Slide 33 text

Ansible Tutorials: http://do.co/ansible