Slide 1

Slide 1 text

Managing WordPress with Ansible 1 — David Murphy @ WordCamp US, December 2015

Slide 2

Slide 2 text

@schwuk http://schwuk.com 2 — David Murphy @ WordCamp US, December 2015

Slide 3

Slide 3 text

3 — David Murphy @ WordCamp US, December 2015

Slide 4

Slide 4 text

Managing WordPress with Ansible 4 — David Murphy @ WordCamp US, December 2015

Slide 5

Slide 5 text

Deploying WordPress with Ansible 5 — David Murphy @ WordCamp US, December 2015

Slide 6

Slide 6 text

why bother? 6 — David Murphy @ WordCamp US, December 2015

Slide 7

Slide 7 text

do it yourself 7 — David Murphy @ WordCamp US, December 2015

Slide 8

Slide 8 text

knowing how to do it yourself 8 — David Murphy @ WordCamp US, December 2015

Slide 9

Slide 9 text

automattion 9 — David Murphy @ WordCamp US, December 2015

Slide 10

Slide 10 text

automattion 10 — David Murphy @ WordCamp US, December 2015

Slide 11

Slide 11 text

automation 11 — David Murphy @ WordCamp US, December 2015

Slide 12

Slide 12 text

why automate things? 12 — David Murphy @ WordCamp US, December 2015

Slide 13

Slide 13 text

if you are going to do something more than once, automate it — me (and many others) 13 — David Murphy @ WordCamp US, December 2015

Slide 14

Slide 14 text

choices 14 — David Murphy @ WordCamp US, December 2015

Slide 15

Slide 15 text

choice #1: software 15 — David Murphy @ WordCamp US, December 2015

Slide 16

Slide 16 text

16 — David Murphy @ WordCamp US, December 2015

Slide 17

Slide 17 text

choice #2: platform 17 — David Murphy @ WordCamp US, December 2015

Slide 18

Slide 18 text

an abundance of choices: Ubuntu • Debian FreeBSD • OpenBSD • NetBSD Fedora • CentOS openSUSE • Slackware Gentoo • Arch Linux CoreOS 18 — David Murphy @ WordCamp US, December 2015

Slide 19

Slide 19 text

they are all good 19 — David Murphy @ WordCamp US, December 2015

Slide 20

Slide 20 text

20 — David Murphy @ WordCamp US, December 2015

Slide 21

Slide 21 text

choice #3: hosting 21 — David Murphy @ WordCamp US, December 2015

Slide 22

Slide 22 text

a plethora of choices: Bluehost • InMotion Hosting • DreamHost HostGator • WP Engine • GoDaddy Pagely • Media Temple DigitalOcean • Linode • Vultr Amazon Web Services Google Cloud Platform Microsoft Azure 22 — David Murphy @ WordCamp US, December 2015

Slide 23

Slide 23 text

shared hosting 23 — David Murphy @ WordCamp US, December 2015

Slide 24

Slide 24 text

virtual private server 24 — David Murphy @ WordCamp US, December 2015

Slide 25

Slide 25 text

cloud 25 — David Murphy @ WordCamp US, December 2015

Slide 26

Slide 26 text

they are not all equal 26 — David Murphy @ WordCamp US, December 2015

Slide 27

Slide 27 text

27 — David Murphy @ WordCamp US, December 2015

Slide 28

Slide 28 text

28 — David Murphy @ WordCamp US, December 2015

Slide 29

Slide 29 text

choice #4: tool 29 — David Murphy @ WordCamp US, December 2015

Slide 30

Slide 30 text

Puppet Chef Salt Ansible 30 — David Murphy @ WordCamp US, December 2015

Slide 31

Slide 31 text

31 — David Murphy @ WordCamp US, December 2015

Slide 32

Slide 32 text

Ansible is a powerful automation tool that you can learn quickly. 32 — David Murphy @ WordCamp US, December 2015

Slide 33

Slide 33 text

inventory playbooks roles 33 — David Murphy @ WordCamp US, December 2015

Slide 34

Slide 34 text

inventory 34 — David Murphy @ WordCamp US, December 2015

Slide 35

Slide 35 text

sample inventory [webservers] www1.example.com www2.example.com [dbservers] db0.example.com db1.example.com 35 — David Murphy @ WordCamp US, December 2015

Slide 36

Slide 36 text

naming patterns [webservers] www[01:50].example.com [databases] db-[a:f].example.com 36 — David Murphy @ WordCamp US, December 2015

Slide 37

Slide 37 text

groups-of-groups [web] host1 host2 [database] host2 host3 [site:children] web database 37 — David Murphy @ WordCamp US, December 2015

Slide 38

Slide 38 text

my inventory [development] my_vagrant_host ansible_sudo=yes [production] wcus.schwuk.com 38 — David Murphy @ WordCamp US, December 2015

Slide 39

Slide 39 text

demo 39 — David Murphy @ WordCamp US, December 2015

Slide 40

Slide 40 text

40 — David Murphy @ WordCamp US, December 2015

Slide 41

Slide 41 text

playbooks 41 — David Murphy @ WordCamp US, December 2015

Slide 42

Slide 42 text

sample playbook --- - hosts: webservers remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=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 42 — David Murphy @ WordCamp US, December 2015

Slide 43

Slide 43 text

modules 43 — David Murphy @ WordCamp US, December 2015

Slide 44

Slide 44 text

yum - name: install the latest version of Apache yum: name=httpd state=latest - name: remove the Apache package yum: name=httpd state=absent - name: install the latest version of Apache from↩ the testing repo yum: name=httpd enablerepo=testing state=present - name: install one specific version of Apache yum: name=httpd-2.2.29-1.4.amzn1 state=present 44 — David Murphy @ WordCamp US, December 2015

Slide 45

Slide 45 text

template # Example from Ansible Playbooks - template: src=/mytemplates/foo.j2 dest=/etc/file.conf↩ owner=bin group=wheel mode=0644 # The same example, but using symbolic modes equivalent to 0644 - template: src=/mytemplates/foo.j2 dest=/etc/file.conf↩ owner=bin group=wheel mode="u=rw,g=r,o=r" 45 — David Murphy @ WordCamp US, December 2015

Slide 46

Slide 46 text

service # Example action to start service httpd, if not running - service: name=httpd state=started # Example action to stop service httpd, if running - service: name=httpd state=stopped # Example action to restart service httpd, in all cases - service: name=httpd state=restarted # Example action to reload service httpd, in all cases - service: name=httpd state=reloaded # Example action to enable service httpd, and not touch↩ the running state - service: name=httpd enabled=yes 46 — David Murphy @ WordCamp US, December 2015

Slide 47

Slide 47 text

modules, modules, modules → command, get_url → apt, apt_key, apt_repository → digital_ocean, linode, ec2, gce, docker → irc, slack, hipchat, mail → mysql_db, mysql_user → git, subversion 47 — David Murphy @ WordCamp US, December 2015

Slide 48

Slide 48 text

install → configure → control 48 — David Murphy @ WordCamp US, December 2015

Slide 49

Slide 49 text

apt → template → service 49 — David Murphy @ WordCamp US, December 2015

Slide 50

Slide 50 text

deploying WordPress 50 — David Murphy @ WordCamp US, December 2015

Slide 51

Slide 51 text

famous 5-minute install1 → download/unzip → create database → edit config → upload 1 http://codex.wordpress.org/InstallingWordPress#Famous5- Minute_Install 51 — David Murphy @ WordCamp US, December 2015

Slide 52

Slide 52 text

a better example → install packages → create database, then database user → download/unzip → edit config → configure webserver → ensure webserver is running 52 — David Murphy @ WordCamp US, December 2015

Slide 53

Slide 53 text

first, some variables vars: db_name: wcus db_user: wcus db_password: correcthorsebatterystaple site_name: wcus.schwuk.com site_alias: wcus 53 — David Murphy @ WordCamp US, December 2015

Slide 54

Slide 54 text

install the packages - name: Install mysql-server apt: name=mysql-server state=present↩ update_cache=yes cache_valid_time=3600 - name: Install apache2 apt: name=apache2 state=present - name: Install libapache2-mod-php5 apt: name=libapache2-mod-php5 state=present - name: Install php5-mysql apt: name=php5-mysql state=present - name: Install python-mysqldb apt: name=python-mysqldb state=present - name: Install python-httplib2 apt: name=python-httplib2 state=present 54 — David Murphy @ WordCamp US, December 2015

Slide 55

Slide 55 text

install the packages, take two - name: Install required packages apt: name: "{{ item }}" state: present update_cache: yes cache_valid_time: 3600 with_items: - mysql-server - apache2 - libapache2-mod-php5 - php5-mysql - python-mysqldb - python-httplib2 55 — David Murphy @ WordCamp US, December 2015

Slide 56

Slide 56 text

setup the database - name: Create WordPress database mysql_db: name: "{{ db_name }}" state: present - name: Create WordPress user mysql_user: name: "{{ db_user }}" password: "{{ db_password }}" priv: "{{ db_name }}.*:ALL" state: present 56 — David Murphy @ WordCamp US, December 2015

Slide 57

Slide 57 text

install WordPress - name: Create directory for WordPress file: path: /srv/{{ site_alias }} state: directory mode: 0755 - name: Get WordPress get_url: url: http://wordpress.org/latest.tar.gz dest: /tmp/wordpress.tar.gz - name: Extract WordPress unarchive: src: /tmp/wordpress.tar.gz dest: /srv/{{ site_alias }} copy: no 57 — David Murphy @ WordCamp US, December 2015

Slide 58

Slide 58 text

edit the config - name: Generate Keys and Salts uri: url: https://api.wordpress.org/secret-key/1.1/salt/ dest: /srv/{{ site_alias }}/keys.php creates: /srv/{{ site_alias }}/keys.php - name: Configure WordPress template: src: wp-config.php dest: /srv/{{ site_alias }}/wordpress/wp-config.php owner: root group: root mode: 0644 58 — David Murphy @ WordCamp US, December 2015

Slide 59

Slide 59 text

wp-config.php

Slide 60

Slide 60 text

configure the webserver - name: Configure webserver template: src: apache-site.conf dest: /etc/apache2/sites-available/{{ site_alias }}.conf owner: root group: root mode: 0644 notify: - restart apache - name: Disable default site_alias command: a2dissite 000-default - name: Enable WordPress site command: a2ensite {{ site_alias }} 60 — David Murphy @ WordCamp US, December 2015

Slide 61

Slide 61 text

handling events handlers: - name: restart apache service: name=apache2 state=restarted 61 — David Murphy @ WordCamp US, December 2015

Slide 62

Slide 62 text

demo 62 — David Murphy @ WordCamp US, December 2015

Slide 63

Slide 63 text

63 — David Murphy @ WordCamp US, December 2015

Slide 64

Slide 64 text

64 — David Murphy @ WordCamp US, December 2015

Slide 65

Slide 65 text

65 — David Murphy @ WordCamp US, December 2015

Slide 66

Slide 66 text

next steps 66 — David Murphy @ WordCamp US, December 2015

Slide 67

Slide 67 text

opinionated 67 — David Murphy @ WordCamp US, December 2015

Slide 68

Slide 68 text

there's more than one way to do it — Perl community (and Larry Wall) 68 — David Murphy @ WordCamp US, December 2015

Slide 69

Slide 69 text

questions? 69 — David Murphy @ WordCamp US, December 2015