Provisioning of a Symfony project

with Ansible

Symfony2 in London 29/10/14

Maxime Thoonsen

@maxthoon

Symfony2

NodeJs

AngularJs

Ansible

Maxime Thoonsen

Dev @Theodo

 

WHAT ABOUT YOU?

PROD

PREPROD

STAGING

LOCAL

PROD + PREPROD + STAGING + N DEV =

WHAT IS ANSIBLE?

Ansible is an automation tool

WHY ANSIBLE?

Ansible is simple

A little more about Ansible

  • Use of SSH
  • Written in Python
  • No agent needed on the server
  • YAML configuration
  • Jinja2 templating (like Twig)

Many modules

  • Command : command, script, shell
  • Database : mongodb, mysql, postgresql, redis, riak
  • Source Control : git, github_hooks
  • System : authorized_key, cron, hostname, ping, user
  • Utilities : assert, debug, fail, include_vars, pause
  • ...

Provisioning with Ansible

  • Tasks
  • Roles
  • Playbook
  • Vagrant

Ansible task

  • Module
  • Variable
  • List
  • Template
  • Condition
  • Handler

Ansible templates

Ansible variables

Ansible handlers

Let's see a role

Let's have a look at a playbook:

Vagrantfile

 

  # Ansible
  config.vm.provision "ansible" do |ansible|
    ansible.sudo = true
    ansible.playbook = "provision/playbook.yml"
    ansible.limit = "vagrant" # hosts group
    ansible.inventory_path = "provision/hosts/vagrant"
    ansible.verbose = "v" #Use vvvv to get more log
  end

Vagrant tasks

Vagrant provisioning

Start a new project

  1. Choose the roles
  2. Define your variables
  3. Update the templates
  4. Define your inventories

Ansible Galaxy

  • Role sharing
  • Role evaluation
  • Versioning
  • CLI Download
ansible-galaxy install kosssi.composer,v1.0.3

Search roles

Search roles

The list of our favorites roles

My symfony playbook

Roles installation

 

ansible-galaxy install -i kosssi.apache,v1.0.1 --force
ansible-galaxy install -i ANXS.mysql,v1.0.2 --force
ansible-galaxy install -i kosssi.php,v1.0.0 --force
ansible-galaxy install -i kosssi.composer,v1.0.3 --force

Write inventories

 

[vagrant]
symfony.dev

[webservers:children]
vagrant

[dbservers:children]
vagrant
[prod]
symfony.prod

[webservers:children]
prod

[dbservers:children]
prod

/provision/hosts/vagrant :

/provision/hosts/prod :

 Write the playbook

 

- name: Provision website
  hosts: webservers
  sudo: yes
  vars_files:
    - vars/php.yml
    - vars/apache.yml
  roles:
    - { role: kosssi.php, tags: php }
    - { role: kosssi.composer, tags: composer }
    - { role: kosssi.apache, tags: apache }
    - { role: www-data, tags: www-data }

Deployement

Feedback

 

  • Many devs like Ansible ! 

  • Few sysadmins appreciate it

  • Now I love Devops !

  • Ansible is easy to learn

Special thanks to

Simon

Follow him !

Nico

(Don't follow him...)

Question ?

Made with Slides.com