Download - DevOps for Humans - Ansible for Drupal Deployment Victory!

Transcript
Page 1: DevOps for Humans - Ansible for Drupal Deployment Victory!

DEVOPS FOR HUMANSF O R D R U P A L D E P L O Y M E N T V I C T O R Y !

DevOps Track - Thursday, June 5, 2014

2014

Page 2: DevOps for Humans - Ansible for Drupal Deployment Victory!

Me

• geerlingguy / Jeff Geerling • Senior Application Developer, Mercy • Owner, Midwestern Mac, LLC

Page 3: DevOps for Humans - Ansible for Drupal Deployment Victory!

Ansible for DevOps

• For sale on LeanPub

• 50% complete

Page 4: DevOps for Humans - Ansible for Drupal Deployment Victory!

This presentation

1. Drupal deployments are hard

2. Ansible is simple and powerful

3. Ansible is great for Drupal deployments (and a lot more)

Page 5: DevOps for Humans - Ansible for Drupal Deployment Victory!

In the Beginning…

• Local Dev: MAMP/WAMP/XAMPP

• Deployments: git  pull  &&  drush  updb  

• Plus 15 other manual deployment steps…

• New servers: manual provisioning

Page 6: DevOps for Humans - Ansible for Drupal Deployment Victory!

http://devopsreactions.tumblr.com/

Page 7: DevOps for Humans - Ansible for Drupal Deployment Victory!

http://devopsreactions.tumblr.com/

Page 8: DevOps for Humans - Ansible for Drupal Deployment Victory!

 _______________________________________    /  I  once  had  to  go  to  a  sysadmin  with  a  \  \  bottle  of  whiskey  to  get  a  deploy.        /    -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                    \      ^__^                    \    (oo)\_______                          (__)\              )\/\                                  ||-­‐-­‐-­‐-­‐w  |                                  ||          ||

@itababy at AnsibleFest NYC, 2014

Page 9: DevOps for Humans - Ansible for Drupal Deployment Victory!

Managed servers: 1

Page 10: DevOps for Humans - Ansible for Drupal Deployment Victory!

Managed servers: 1

circa

(Dries)

Page 11: DevOps for Humans - Ansible for Drupal Deployment Victory!

Managed servers: 50+

UAT

Test

Prod

Page 12: DevOps for Humans - Ansible for Drupal Deployment Victory!

Managed servers: 50+

UAT

Test

Prod

Dev

Page 13: DevOps for Humans - Ansible for Drupal Deployment Victory!

Managed servers: 50+

UAT

Test

Prod

circa Dev

Page 14: DevOps for Humans - Ansible for Drupal Deployment Victory!

The Simsons™ and © Fox and its related companies. All rights reserved.

Page 15: DevOps for Humans - Ansible for Drupal Deployment Victory!

DevOps

• Solving Modern Problems:

• multi-server infrastructure (beyond LAMP)

• cloud provisioning, auto-scaling

• testable infrastructure

Page 16: DevOps for Humans - Ansible for Drupal Deployment Victory!

 _______________________________________    /  It  should  take  less  time  to  rebuild  a  \  \  server  than  to  log  in  and  fix  it.          /    -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                    \      ^__^                    \    (oo)\_______                          (__)\              )\/\                                  ||-­‐-­‐-­‐-­‐w  |                                  ||          ||

http://www.slideshare.net/ItamarHassin/monitordriven-development-using-ansible-34920480

Page 17: DevOps for Humans - Ansible for Drupal Deployment Victory!
Page 18: DevOps for Humans - Ansible for Drupal Deployment Victory!

Puppet Chef Salt Ansible

Initial release 2005 2009 2011 2012

Configuration Language DSL Ruby/DSL YAML YAML

Template Language ERB ERB Jinja2 Jinja2

Agentless ✓

Simple ad-hoc task execution ✓ ✓

GitHub ★s* 2,239 2,729 3,531 6,202

*As of 2014/06/02. Just a reference point. Stars don’t mean much in the grand scheme of things ;-)

Current solutions

Page 19: DevOps for Humans - Ansible for Drupal Deployment Victory!

Puppet Chef Salt Ansible

Initial release 2005 2009 2011 2012

Configuration Language DSL Ruby/DSL YAML YAML

Template Language ERB ERB Jinja2 Jinja2

Agentless ✓

Simple ad-hoc task execution ✓ ✓

GitHub ★s* 2,239 2,729 3,531 6,202

Just like Drupal 8!

Just like Twig!

*As of 2014/06/02. Just a reference point. Stars don’t mean much in the grand scheme of things ;-)

Current solutions

Page 20: DevOps for Humans - Ansible for Drupal Deployment Victory!

Puppet Chef Salt Ansible

Initial release 2005 2009 2011 2012

Configuration Language DSL Ruby/DSL YAML YAML

Template Language ERB ERB Jinja2 Jinja2

Agentless ✓

Simple ad-hoc task execution ✓ ✓

GitHub ★s* 2,239 2,729 3,531 6,202

Just like Drupal 8!

Just like Twig!

*As of 2014/06/02. Just a reference point. Stars don’t mean much in the grand scheme of things ;-)

#HugOps

Current solutions

Page 21: DevOps for Humans - Ansible for Drupal Deployment Victory!

Who uses ?

(and me: Server Check.in, Hosted Apache Solr, Midwestern Mac, LLC)

Page 22: DevOps for Humans - Ansible for Drupal Deployment Victory!

First Steps with

Page 23: DevOps for Humans - Ansible for Drupal Deployment Victory!

Inventory

Page 24: DevOps for Humans - Ansible for Drupal Deployment Victory!

Inventory

[lamp]  example.com  ![lamp:vars]  ansible_ssh_user=johndoe  ansible_ssh_port=2222

(save in /etc/ansible/hosts)

Page 25: DevOps for Humans - Ansible for Drupal Deployment Victory!

Inventory

[lamp]  example.com  ![lamp:vars]  ansible_ssh_user=johndoe  ansible_ssh_port=2222

(save in /etc/ansible/hosts)

Group name

Page 26: DevOps for Humans - Ansible for Drupal Deployment Victory!

Inventory

[lamp]  example.com  ![lamp:vars]  ansible_ssh_user=johndoe  ansible_ssh_port=2222

(save in /etc/ansible/hosts)

Group nameHosts in group (just one, for now)

Page 27: DevOps for Humans - Ansible for Drupal Deployment Victory!

Inventory

[lamp]  example.com  ![lamp:vars]  ansible_ssh_user=johndoe  ansible_ssh_port=2222

(save in /etc/ansible/hosts)

Group nameHosts in group (just one, for now)

Variables(for all hosts in group)

Page 28: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook Task

Page 29: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook Task

-­‐  name:  Ensure  Apache  is  installed.      apt:  pkg=apache2  state=latest

Page 30: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook Task

-­‐  name:  Ensure  Apache  is  installed.      apt:  pkg=apache2  state=latest

Documentation

Page 31: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook Task

-­‐  name:  Ensure  Apache  is  installed.      apt:  pkg=apache2  state=latest

Documentation

Module

Page 32: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook Task

-­‐  name:  Ensure  Apache  is  installed.      apt:  pkg=apache2  state=latest

Documentation

ArgumentsModule

Page 33: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook-­‐-­‐-­‐  -­‐  name:  Ensure  Apache/PHP  is  installed.      apt:  "pkg={{  item  }}  state=latest"      with_items:          -­‐  apache2          -­‐  php5-­‐common          -­‐  libapache2-­‐mod-­‐php5          -­‐  php5-­‐cli  !-­‐  name:  Ensure  Apache  is  started.      service:  name=apache2  state=started

(save as web.yml)

Page 34: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook

-­‐-­‐-­‐  -­‐  hosts:  lamp      sudo:  yes  !    tasks:          -­‐  apt:  update_cache=yes  !        -­‐  include:  web.yml

(save as playbook.yml)

Page 35: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook

-­‐-­‐-­‐  -­‐  hosts:  lamp      sudo:  yes  !    tasks:          -­‐  apt:  update_cache=yes  !        -­‐  include:  web.yml

(save as playbook.yml)

Name of group/host defined in inventory

Page 36: DevOps for Humans - Ansible for Drupal Deployment Victory!

Playbook

-­‐-­‐-­‐  -­‐  hosts:  lamp      sudo:  yes  !    tasks:          -­‐  apt:  update_cache=yes  !        -­‐  include:  web.yml

(save as playbook.yml)

Name of group/host defined in inventory

Include the playbook we created earlier

Page 37: DevOps for Humans - Ansible for Drupal Deployment Victory!

ansible-­‐playbook run

Page 38: DevOps for Humans - Ansible for Drupal Deployment Victory!

ansible-­‐playbook run

Page 39: DevOps for Humans - Ansible for Drupal Deployment Victory!

Ansible ♥ Vagrant

Page 40: DevOps for Humans - Ansible for Drupal Deployment Victory!

Ansible ♥ Vagrant

• First-class provisioner

• Inside Vagrantfile:

       config.vm.provision  "ansible"  do  |ansible|              ansible.playbook  =  "playbook.yml"              ansible.inventory_path  =  "inventory-­‐vagrant"        end

Page 41: DevOps for Humans - Ansible for Drupal Deployment Victory!

Deploy Drupal 8 with

Page 42: DevOps for Humans - Ansible for Drupal Deployment Victory!

-­‐-­‐-­‐  -­‐  hosts:  d8      sudo:  yes  !    pre_tasks:          -­‐  apt:  update_cache=yes          -­‐  apt_repository:  >                  repo='ppa:ondrej/php5-­‐oldstable'  !    roles:          -­‐  geerlingguy.apache          -­‐  geerlingguy.mysql          -­‐  geerlingguy.php          -­‐  geerlingguy.php-­‐mysql          -­‐  geerlingguy.postfix          -­‐  geerlingguy.drupal

Page 43: DevOps for Humans - Ansible for Drupal Deployment Victory!

-­‐-­‐-­‐  -­‐      !            -­‐          -­‐                  repo='ppa:ondrej/php5-­‐oldstable'!            -­‐          -­‐          -­‐          -­‐          -­‐          -­‐  

(this actually works)

Page 44: DevOps for Humans - Ansible for Drupal Deployment Victory!

00:03:14 later…

Page 45: DevOps for Humans - Ansible for Drupal Deployment Victory!

Demo

Page 46: DevOps for Humans - Ansible for Drupal Deployment Victory!

Ansible Roles• Encapsulation for configuration/tasks

Page 47: DevOps for Humans - Ansible for Drupal Deployment Victory!

Ansible Roles• Encapsulation for configuration/tasks

Ansible Role

files/

tasks/

handlers/

vars/ meta/

templates/

Page 48: DevOps for Humans - Ansible for Drupal Deployment Victory!

Drupal Deployment Role

deploy/ roles/ site-deploy/ playbook.yml

Page 49: DevOps for Humans - Ansible for Drupal Deployment Victory!

Drupal Deployment Role

deploy/ roles/ site-deploy/ playbook.yml

Custom role!'site-deploy'

Page 50: DevOps for Humans - Ansible for Drupal Deployment Victory!

tasks

-­‐-­‐-­‐  -­‐  name:  Run  drush  commands  to  update  site.      command:  >          drush  -­‐y  {{  item  }}          chdir={{  drupal_core_path  }}      with_items:            -­‐  "cset  system.site  name  '{{  site_name  }}'"          -­‐  "rap  'anonymous'  'search  content'"      notify:  restart  webserver

site-deploy/tasks/main.yml

Page 51: DevOps for Humans - Ansible for Drupal Deployment Victory!

vars

-­‐-­‐-­‐  site_name:  "Ansible  Deployment"  drupal_core_path:  /var/www/drupal-­‐8.x-­‐dev

site-deploy/vars/main.yml

Page 52: DevOps for Humans - Ansible for Drupal Deployment Victory!

handlers

-­‐-­‐-­‐  -­‐  name:  restart  webserver      service:  >          name=apache2          state=restarted      sudo:  yes

site-deploy/handlers/main.yml

Page 53: DevOps for Humans - Ansible for Drupal Deployment Victory!

deploy/ roles/ site-deploy/ playbook.yml

tasks/main.yml vars/main.yml handlers/main.yml

Drupal Deployment Role

Page 54: DevOps for Humans - Ansible for Drupal Deployment Victory!

deploy/ roles/ site-deploy/ playbook.yml

Drupal Deployment Role

Page 55: DevOps for Humans - Ansible for Drupal Deployment Victory!

playbook

-­‐-­‐-­‐  -­‐  hosts:  d8      roles:          -­‐  site-­‐deploy

playbook.yml

Page 56: DevOps for Humans - Ansible for Drupal Deployment Victory!

Demo

Page 57: DevOps for Humans - Ansible for Drupal Deployment Victory!

Notifications

-­‐  name:  Send  IRC  message.      irc:  >          channel='#drupalcon'          server='chat.freenode.net'          nick='ansible-­‐ninja'          msg={{  irc_message  }}      delegate_to:  127.0.0.1

(also inside playbook.yml)

Page 58: DevOps for Humans - Ansible for Drupal Deployment Victory!

-­‐-­‐-­‐  -­‐  hosts:  d8      sudo:  yes  !    pre_tasks:          -­‐  apt:  update_cache=yes          -­‐  apt_repository:  >                  repo='ppa:ondrej/php5-­‐oldstable'  !    roles:          -­‐  geerlingguy.apache          -­‐  geerlingguy.mysql          -­‐  geerlingguy.php          -­‐  geerlingguy.php-­‐mysql          -­‐  geerlingguy.postfix          -­‐  geerlingguy.drupal          -­‐  site-­‐deploy

Page 59: DevOps for Humans - Ansible for Drupal Deployment Victory!

-­‐-­‐-­‐  -­‐  hosts:  d8      sudo:  yes  !    pre_tasks:          -­‐  apt:  update_cache=yes          -­‐  apt_repository:  >                  repo='ppa:ondrej/php5-­‐oldstable'  !    roles:          -­‐  geerlingguy.apache          -­‐  geerlingguy.mysql          -­‐  geerlingguy.php          -­‐  geerlingguy.php-­‐mysql          -­‐  geerlingguy.postfix          -­‐  geerlingguy.drupal          -­‐  site-­‐deploy

Add to provisioningplaybook.yml

Page 60: DevOps for Humans - Ansible for Drupal Deployment Victory!
Page 61: DevOps for Humans - Ansible for Drupal Deployment Victory!

reverse-proxy.yml

webserver.yml

database.yml

search.yml

cache.yml

Page 62: DevOps for Humans - Ansible for Drupal Deployment Victory!

reverse-proxy.yml

webserver.yml

database.yml

search.yml

cache.yml

infrastructure-playbook.yml

Page 63: DevOps for Humans - Ansible for Drupal Deployment Victory!

-­‐-­‐-­‐  -­‐  hosts:  all      roles:          -­‐  security          -­‐  monitoring          -­‐  fileshare  !-­‐  hosts:  webservers      roles:          -­‐  nginx          -­‐  php          -­‐  drupal  !-­‐  hosts:  database      roles:          -­‐  postgres

Page 64: DevOps for Humans - Ansible for Drupal Deployment Victory!

for Drupal Deployment Victory!

Page 65: DevOps for Humans - Ansible for Drupal Deployment Victory!

for Drupal Deployment Victory!

• Easy to get started

Page 66: DevOps for Humans - Ansible for Drupal Deployment Victory!

for Drupal Deployment Victory!

• Easy to get started

• OH: “it works on my machine”

• sysadmin burnout

Page 67: DevOps for Humans - Ansible for Drupal Deployment Victory!

for Drupal Deployment Victory!

• Easy to get started

• OH: “it works on my machine”

• sysadmin burnout

• You’ll actually enjoy it!

Page 68: DevOps for Humans - Ansible for Drupal Deployment Victory!

for Drupal Deployment Victory!

• Easy to get started

• OH: “it works on my machine”

• sysadmin burnout

• You’ll actually enjoy it!

• …but BEWARE THE GOLDEN HAMMER!

Page 69: DevOps for Humans - Ansible for Drupal Deployment Victory!

Things I wanted to cover, but didn’t have time

Page 70: DevOps for Humans - Ansible for Drupal Deployment Victory!

• Ansible ♥’s:

• Packer

• Docker

• [AWS|DO|Linode|Rackspace|etc.]

Things I wanted to cover, but didn’t have time

Page 71: DevOps for Humans - Ansible for Drupal Deployment Victory!

• Ansible ♥’s:

• Packer

• Docker

• [AWS|DO|Linode|Rackspace|etc.]

• Delegation, notifications, ad-hoc commands, async commands, rolling updates, prompts, Ansible Vault, wait_for, forks, dynamic inventory, and oh-so-much-more…

Things I wanted to cover, but didn’t have time

Page 73: DevOps for Humans - Ansible for Drupal Deployment Victory!

• Download Ansible

• Automate!

• Buy my book :)

Things you will do now:

Page 74: DevOps for Humans - Ansible for Drupal Deployment Victory!

WHAT DID YOU THINK?E VA LUAT E T H I S S E S S I O N :

A U S T I N 2 0 1 4 . D R U PA L . O R G / S C H E D U L E

Thank you!

2014