Slide 1

Slide 1 text

Managing Modern Infrastructure with Ansible Joe Ferguson https://github.com/svpernova09/ModernInfrastructureWithAnsible

Slide 2

Slide 2 text

Who Am I? Joe Ferguson PHP Developer Senior Full Stack Dev @ Preteckt Open Source Geek ⚽,, and fan Twitter: @JoePFerguson

Slide 3

Slide 3 text

Ansible for DevOps https://leanpub.com/ansible-for-devops

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

pip install ansible

Slide 6

Slide 6 text

Ansible Concepts Modules Standalone work units to perform a task Inventory Configuration Declaration of target systems to perform tasks upon Playbooks Complete set of roles / list of actions to take

Slide 7

Slide 7 text

Command Module

Slide 8

Slide 8 text

Command Module

Slide 9

Slide 9 text

Command Module

Slide 10

Slide 10 text

Create Ansible Playbook

Slide 11

Slide 11 text

Running Our Ansible Playbook

Slide 12

Slide 12 text

Ansible Variable Precedence http://docs.ansible.com/ansible/playbooks_variables.html

Slide 13

Slide 13 text

Ansible Variable Precedence • command line values (eg “-u user”) • role defaults • inventory file or script group vars • inventory group_vars/all • playbook group_vars/all • inventory group_vars/* • playbook group_vars/* • inventory file or script host vars

Slide 14

Slide 14 text

Reusing Playbooks from others

Slide 15

Slide 15 text

Ansible Galaxy Authors

Slide 16

Slide 16 text

Adding geerlingguy.php

Slide 17

Slide 17 text

Overriding Variables

Slide 18

Slide 18 text

Overriding Variables

Slide 19

Slide 19 text

Adding ansible-role-php

Slide 20

Slide 20 text

Adding ansible-role-php

Slide 21

Slide 21 text

Running ansible-role-php

Slide 22

Slide 22 text

Production Inventory

Slide 23

Slide 23 text

Staging Inventory

Slide 24

Slide 24 text

Dev Inventory

Slide 25

Slide 25 text

ansible_playbook -i prod.ini ansible_playbook -i staging.ini ansible_playbook -i dev.ini

Slide 26

Slide 26 text

Ansible can deploy your code

Slide 27

Slide 27 text

General Ansible Advice Use environment based playbooks & inventory files for clear separation & to easily handle one off differences Use Python or some other environment variable system for managing your secrets! Couple variables to the most focused point, then raise their scope as you need

Slide 28

Slide 28 text

Ansible Tower https://www.ansible.com/products/tower

Slide 29

Slide 29 text

Ansible Tower https://www.ansible.com/products/tower/pricing

Slide 30

Slide 30 text

AWX - Open Source Tower

Slide 31

Slide 31 text

AWX - Open Source Tower

Slide 32

Slide 32 text

Python for PHP Devs Python PHP Composer Packagist composer.json FPM ??? composer.lock Pip PyPi & Others requirements.txt WSGI VirtualEnv LOL lock files

Slide 33

Slide 33 text

Virtual Environments

Slide 34

Slide 34 text

Install Dependencies

Slide 35

Slide 35 text

Install Dependencies

Slide 36

Slide 36 text

Freeze Dependencies

Slide 37

Slide 37 text

Our Virtual Env

Slide 38

Slide 38 text

Building a Deploy Playbook http://vcdt.joeferguson.me/

Slide 39

Slide 39 text

Playbook File

Slide 40

Slide 40 text

deploy-vcdt-app Role

Slide 41

Slide 41 text

deploy-vcdt-app Role

Slide 42

Slide 42 text

Using Jinja2 Templates

Slide 43

Slide 43 text

Update the Repository

Slide 44

Slide 44 text

Composer Install

Slide 45

Slide 45 text

Application Setup

Slide 46

Slide 46 text

Job’s Done!

Slide 47

Slide 47 text

Break Up Large YAML

Slide 48

Slide 48 text

System Maintenance

Slide 49

Slide 49 text

System Maintenance

Slide 50

Slide 50 text

Install & Configure Certbot

Slide 51

Slide 51 text

Create SSL & Cron

Slide 52

Slide 52 text

Combine SSL For HAProxy

Slide 53

Slide 53 text

Delayed Service Restarting

Slide 54

Slide 54 text

Renewal Post Hook Script

Slide 55

Slide 55 text

Renewal Post Hook Script

Slide 56

Slide 56 text

Install Docker

Slide 57

Slide 57 text

Install Docker

Slide 58

Slide 58 text

Add Users

Slide 59

Slide 59 text

Looping over Arrays (Hashes)

Slide 60

Slide 60 text

Directory Layout

Slide 61

Slide 61 text

Directory Layout

Slide 62

Slide 62 text

Directory Layout

Slide 63

Slide 63 text

Keep Your Secrets Secret!

Slide 64

Slide 64 text

Rolling Updates: Serial

Slide 65

Slide 65 text

Maximum Failure

Slide 66

Slide 66 text

Joe Ferguson Twitter: @JoePFerguson Email: [email protected] Contact Info: Thanks!