24
Ansible, EC2 and PHP Easy Orchestration www.bipsync.com

Ansible, PHP and EC2

Embed Size (px)

Citation preview

Ansible, EC2 and PHPEasy Orchestration

www.bipsync.com

www.bipsync.com

IANAL

www.bipsync.com

IANASWANB

www.bipsync.com

In March 2014…

www.bipsync.com

• Ad hoc local development in OS X

• Hand-built production systems in AWS

• Various installation notes kept in wiki

And now…

www.bipsync.com

• Local development in Vagrant VMs

• Virtual Machines provisioned by Ansible playbooks

• Production systems provisioned by playbooks

• Ansible playbooks are living documentation

Application environment

www.bipsync.com

• Hosted in Virtual Private Cloud (VPC)

• Load balanced application web servers

• Worker instances

• Search cluster

• Database cluster

www.bipsync.com

App

Worker

Database

Vagrant VM

Search

www.bipsync.com

App App

Worker Search

Database

Load Balancer

VPC

DatabaseDatabase

Search

Ansible tasks

www.bipsync.com

- name: Install php-fpm and dependencies ! yum: name={{ item }} state=present ! with_items: ! - php ! - php-fpm ! - php-mysql

Ansible playbooks

www.bipsync.com

- name: Install MySQL, Nginx, and PHP-FPM

hosts: webservers

roles: ! - common ! - mysql ! - nginx ! - php-fpm

Provisioning Vagrant VMs

www.bipsync.com

1. Define an Ansible playbook

2. Define a vagrant configuration file which runs the playbook

3. vagrant up

Provisioning in EC2

www.bipsync.com

1. Define an Ansible playbook

2. Create an instance from an Amazon Machine Image (AMI) within a given subnet

3. Store relevant outcomes as facts - allows us to refer to them later in the playbook

4. Wait until SSH is available, perform additional provisioning

Demo

www.bipsync.com

Taking it further

www.bipsync.com

1. Master playbook includes playbooks sequentially

2. Facts are maintained from one playbook to the next

3. Once all resources are available, configuration playbooks use facts to connect them together

www.bipsync.com

deploy_all.yml

deploy_vpc.yml deploy_elb.yml deploy_app.yml

deploy_worker.ymldeploy_search.ymldeploy_db.yml

configure.yml

Demo

www.bipsync.com

Provisioning PHP

www.bipsync.com

• Bipsync’s OS of choice is Ubuntu

• We use semi-official packages from https://launchpad.net/~ondrej/+archive/ubuntu/php5

• Installation (PHP-FPM, PECL, config) is pretty straightforward…

• But not totally straightforward

Demo

www.bipsync.com

What else do we do?

www.bipsync.com

• Install and configure Supervisor for long running tasks

• Cron jobs

• Upgrades

• Migrations

• Continuous integration

Why is this cool?

www.bipsync.com

1. Lowers risk

2. Breaks down barriers

3. Enhances scalability

4. Fits the programmer’s mindset

5. Lots of scrolling text on your terminal

Words of warning

www.bipsync.com

• Beware Ansible bugs - turn on termination protection

• Provisioning can take time - make use of AMIs

• Costs can escalate quickly - look at Eucalyptus

• It’s not programming, it’s scripting

Further Reading

www.bipsync.com

• Ansible Up and Running (Loren Hochstein) - Free preview at http://www.ansible.com/ansible-book

• Vagrant Cookbook (Erika Heidi)

• https://groups.google.com/forum/#!forum/ansible-project

Thanks! Questions? !

@craigmarvelley @neveroutofbeta https://www.bipsync.com