Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Deploying Symfony2 app with Ansible

7,437 views

Published on

Ansible overview, architecture and concepts.
What is deploy? And how to deploying Symfony2 app with Ansible.

Thanks for http://www.slideshare.net/ramondelafuente/ansible-projectdeploy/.

Published in: Engineering

Deploying Symfony2 app with Ansible

  1. 1. Roman R.
  2. 2. About me - Software Engineer at EPAM - @co-organizer Lviv GDG - @founder 2enota Roman Rodomansky itspoma@gmail.com github.com/itspoma skype: roman.rodomanskyy linkedin.com/in/rodomansky
  3. 3. 1) Ansible overview 2) Ansible architecture and concepts 3) What is deploy? 4) Deploying Symfony2 app with Ansible Agenda
  4. 4. - python-powered redically simple IT automation tool - is optimized for easy automation, review, editing, & auditability - free, open source - simply - clear (anyone) - fast (to learn, to setup) - complete (modules) - efficient (runs on OpenSSH) - secure (without agents) What is Ansible?
  5. 5. - configuration management - application deployment - multi-tier orchestration - cloud provisioning For what Ansible?
  6. 6. - agentless architecture - management over SSH (no custom PKI-SSH-based, no external databases, no daemons, does not leave software installed) - developer friendly (configuration as data, not code) - batteries-included (usefull modules) - dead simple - release cycles are usually about two months long Ansible features
  7. 7. Who uses Ansible?
  8. 8. Who uses Ansible? 20.01.2014
  9. 9. - fabric (python library) - capistrano (capifony) - puppet - chef - saltstack - idephix, magellanes, deployer, rocketeer (php) Other tools
  10. 10. - required Python 2.6 - or Python 2.5 (with additional paramiko, PyYAML, python-jinja2 and httplib2 modules) - Windows isn’t supported for the control machine (starting with 1.8 will be fully support Windows) - includes Red Hat, Debian, CentOS, OS X, any of the BSDs, and so on Control Machine Requirements
  11. 11. - Python 2.4 or later - if Python 2.5, then with python-simplejson modules - ansible_python_interpreter to point at your 2.x Python - starting in version 1.7, ansible contains support for managing windows machines Managed Node Requirements
  12. 12. - 1.9-dev “Dancing In the Street” - 1.8 “You Really Got Me” Nov 26, 2014 - new Jinja2 filters, fixed a log of modules bugs, new system, variables, new modules, docker support, etc - 1.7 “Summer Nights” Sep 24, 2014 Versions
  13. 13. Ansible Galaxy
  14. 14. Ansible Tower
  15. 15. Ansible Tower
  16. 16. - from git - from os packages (recommend If you are wishing to run the latest released version) - from pip (recommended to use Python package manager for other cases) Install & Configure
  17. 17. - Paramiko (python ssh module) - SSH (OpenSSH) - local Connection types
  18. 18. Ansible architecture
  19. 19. [web] webserver-1.example.com webserver-2.example.com [db] dbserver-1.example.com Host Inventory: Basics
  20. 20. [web] webserver-[01:25].example.com webserver-2.example.com [db] dbserver-[a:f].example.com Host Inventory: Ranges
  21. 21. [all:children] all-local all-stage [all-local:children] web-local db-local [all-stage:children] web-stage db-stage Host Inventory: child groups [web-stage:children] web-stage-testing web-stage-production [db-stage:children] db-stage-testing db-stage-production [web-stage-testing] testing-red [web-stage-production] production [web-local] vagrant [db-local] vagrant
  22. 22. non standart SSH-ports: webserver-3.example.com:2222 SSH tunnel: myhost ansible_ssh_port=5555 ansible_ssh_host=192.168.0.1 Host Inventory: More
  23. 23. ansible <host-pattern> [options] vm$ cd demo1/ vm$ ansible all -m ping vm$ ansible all -m setup vm$ ansible all -a "grep -c processor /proc/cpuinfo" vm$ ansible all -a "uptime" vm$ ansible all -a "uptime" -f 10 Demo
  24. 24. - playbooks - plays - tasks and handlers - modules - variables Ansible concepts
  25. 25. playbooks contains plays plays contains tasks tasks contains modules handels can be triggered by tasks, and will run at the end, once Playbooks
  26. 26. a tasks calls a module, and may have parameters Tasks
  27. 27. Modules May 2013 - 72, October 2014 - 175, February 2015 - 1933 modules on Galaxy
  28. 28. Modules list
  29. 29. - package management: yum, apt - remove execution: command, shell - service management: service - file handling: copy, template - scm: git, subversion Modules examples
  30. 30. - monitoring: monit, nagios, haproxy, etc - development: jenkins, drush, solr, scala, maven, etc - web: Varnish, apache, composer, tomcat, symfony2, etc - networking: tor, RabbitMQ, iptables, etc - cloud: stash-docker, OpenStack, etc Modules examples #2
  31. 31. Module: copy and template
  32. 32. Module: apt and yum
  33. 33. Simple playbook
  34. 34. - playbooks - inventory (group vars, host vars) - command line (ansible-playbook -e “uservar=vagrant”) - discovered variables (facts) Variables
  35. 35. Ansible Directory Structure
  36. 36. ls demo2-*/ ls demo3-*/ Demo
  37. 37. Variables
  38. 38. Facts - discovered variables about systems - ansible -m setup <hostname>
  39. 39. Using facts
  40. 40. Variables (example of group-var)
  41. 41. Variables (example of host-vars)
  42. 42. - project organization tool - reusable components - defined filesystem structure - show: parameterized roles Roles
  43. 43. Roles
  44. 44. - failed_when - changed_when - until - ignore_errors - {{ lookup(‘file’, ‘test.pub’) }} - etc Advanced playbook features
  45. 45. Usage: ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] file_name Ansible vault
  46. 46. App deploy strategies - basic file transfer (via ftp/scp) - using Source Control - using Build Scripts and other Tools
  47. 47. http://symfony.com/doc/current/cookbook/deployment/tools.html 1) Upload your modified code 2) Update your vendor dependencies (composer) 3) Running database migrations 4) Updated assetic assets 5) Clearing your cache 6) Other things Symfony deployment
  48. 48. Symfony deployment $ git pull $ php composer.phar install $ php app/console doctrine:migration:migrate --no-iteraction $ php app/console assets:install web --symlink $ php app/console assets:dump --env=prod $ php app/console cache:clear
  49. 49. Directory structure
  50. 50. 1) Upload your modified code - name: Pull sources from the repository. git: repo={{repo}} dest={{dest}} version={{branch}} when: project_deploy_strategy == “git” module “synchronize” for rsync Symfony deployment
  51. 51. 2) Update your vendor dependencies (composer) - name: Install composer get_url: url=https://getcomposer.org/composer.phar dest={{project_root}}/composer.phar mode=0755 validate_certs=no - name: Run composer install shell: cd {{project_root}}/releases/{{release}} && {{path}} {{project_root}}/composer.phar install {{project_composer_opts}} Symfony deployment
  52. 52. 3) Running database migrations - name: Run migrations shell: cd {{project_root}}/releases/{{release}} && if $(grep doctrine-migrations-bundle composer.json); then {{symfony2_project_php_path}} app/console doctrine:migrations:migrate -n; fi Symfony deployment
  53. 53. 4) Updated assetic assets - name: Dump assets shell: cd {{project_root}}/releases/{{release}} && {{symfony2_project_php_path}} app/console assetic:dump --env={{symfony2_project_env}} {{symfony2_project_console_opts}} Symfony deployment
  54. 54. 5) Clearing your cache - name: Clear cache shell: cd {{project_root}}/releases/{{release}} && {{symfony2_project_php_path}} app/console cache:clear --env={{symfony2_project_env}} Symfony deployment
  55. 55. less than 50 lines of “code” less than 10 tasks less than 5 variables Complicated?
  56. 56. Easy way https://galaxy.ansible.com/list#/roles/639 https://github.com/servergrove/ansible-symfony2
  57. 57. active release: "A-OK" ➙ failure deploying "APP" ➙ rollback ➙ active release: "A-OK" active release: "A-OK" ➙ deploying "BORKED" ➙ fail Deployment rollback
  58. 58. https://github.com/itspoma/epam-symfony2-ansible https://galaxy.ansible.com/ Roman R. Resources
  59. 59. Thanks! - name: questions? copy: src=audience desc=narrator

×