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.

Let's Get Acquainted: Ansible! / Symfony Camp UA 2014

Let's Get Acquainted: Ansible!

Let's Get Acquainted: Ansible! / Symfony Camp UA 2014

  1. 1. Igor Brovchenko Let's Get Acquainted:
  2. 2. About me • Engineer • Chief Software Engineer at Swivl • Symfony Camp UA Igor Brovchenko igor.Brovchenko@gmail.com @tigordev
  3. 3. What is Ansible? • Ansible is an IT automation tool (Python) • Free, open source (github) • Simply • Clear (anyone) • Fast (to learn, setup) • Complete (modules) • Efficient (runs on OpenSSH) • Secure (without agents)
  4. 4. Use cases • Server provisioning • Server orchestration • Application deployment • Continues Integration • …
  5. 5. Who uses Ansible? Over 1 Million Downloads Over 900 contributors and 8000 ★s on GitHub
  6. 6. Other tools • fabric • capistrano (capifony) • puppet • chef • saltstack
  7. 7. Ansible 1.7.2 • Development - 1.8 • A new major release of Ansible approximately every 2 months.
  8. 8. Control Machine Requirements • Red Hat • Debian • CentOS • OS X • any of the BSDs • Windows isn’t supported for the control machine • Ansible 1.8:Windows will be fully supported Python 2.6
  9. 9. Managed Node Requirements • Python 2.4 • Starting in version 1.7, Ansible contains support for managing Windows machines
  10. 10. https://galaxy.ansible.com/
  11. 11. http://www.ansible.com/tower
  12. 12. Symfony Deployment 1. Update the code 2. Update vendor dependencies 3. Running database migrations 4. Update Assetic Assets 5. Clearing the cache 6. Other Things…
  13. 13. Symfony Deployment $ git pull $ php composer.phar install $ php app/console doctrine:migrations:migrate —no-interaction $ php app/console assets:install web —symlink $ php app/console assetic:dump --env=prod $ php app/console cache:clear
  14. 14. Directory Structure `-- /var/www/example.com |-- current → /var/www/example.com/releases/20141012131539 |-- releases | `-- 20141012131539 | `-- 20141009150741 | `-- 20141031145325 `-- shared |-- web | `-- uploads |-- logs `-- config `-- parameters.yml
  15. 15. Installing the Control Machine (Mac OSX) $ brew update $ brew install ansible $ ansible-galaxy install servergrove.symfony2
  16. 16. Installing the Control Machine (Mac OSX) $ ls /usr/local/etc/ansible hosts roles $ ls /usr/local/etc/ansible/hosts/roles servergrove.symfony2
  17. 17. Deploy $ ansible-playbook app/config/playbook_deploy.yml $ ansible-playbook -l localhost app/config/playbook_deploy.yml -vvv
  18. 18. playbook_deploy.yml - hosts: stage-app vars: symfony2_project_name: Deploy the application symfony2_project_root: /var/www/example.com symfony2_project_release: '{{ current_timestamp.stdout }}' symfony2_project_repo: git@github.com:ingvar/ExampleApp.git symfony2_project_branch: release symfony2_project_php_path: /usr/local/php55/bin/php symfony2_project_env: prod symfony2_project_console_opts: '--no-debug' symfony2_project_composer_opts: '--no-dev --optimize-autoloader' roles: - servergrove.symfony2 tasks: - local_action: osx_say msg="Deployment complete." voice=Zarvox
  19. 19. Inventory (hosts) [localhost] localhost ansible_connection=local [stage-app] stage.example.com ansible_connection=ssh [prod-app] www1.example.com www2.example.com www[10:50].example.com [databases] db-[a:f].example.com
  20. 20. Inventory (hosts) $ ansible localhost -m command "echo "Hello World" " $ ansible prod-app -m ping
  21. 21. Ansible Structure • Inventory • Modules • Ad Hoc Commands • Playbooks • Tasks • Variables • Templates • Handlers • Roles
  22. 22. Modules • Cloud • Commands • Database • Files • Internal • Inventory • Messaging • Monitoring • Net Infrastructure • Network • Notification • Packaging • Source Control • System • Utilities • Web Infrastructure • Windows
  23. 23. Modules • Cloud (DO, AWS,Azure, GCE, Docker) • DB (Mongo, MySQL, Postgres, Redis, Riak) • Messaging (RabbitMQ) • Monitoring (Zabbix, Monit, Nagios, New Relic…) • Web (apache, supervisord…) • Docker • Vagrant • …
  24. 24. Notification Modules • flowdock • hipchat • irc • jabber • slac • sns • twilio • …
  25. 25. Cron module # Ensure a job that runs at 2 and 5 exists. # Creates an entry like "* 5,2 * * ls -alh > /dev/null" - cron: name="check dirs" hour="5,2" job="ls -alh > /dev/null" # Ensure an old job is no longer present. Removes any job that is prefixed # by "#Ansible: an old job" from the crontab - cron: name="an old job" state=absent # Creates an entry like "@reboot /some/job.sh" - cron: name="a job for reboot" special_time=reboot job="/some/job.sh" # Creates a cron file under /etc/cron.d - cron: name="yum autoupdate" weekday="2" minute=0 hour=12 user="root" job="YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate" cron_file=ansible_yum-autoupdate # Removes a cron file from under /etc/cron.d
  26. 26. http://docs.ansible.com/guide_vagrant.html
  27. 27. Roles • YAML • Documentation • Modules (task) • Ansible Galaxy
  28. 28. Tasks (main.yml)
  29. 29. Templates • Templates are processed by the Jinja2 templating language (http://jinja.pocoo.org/docs/dev/templates/) • Powerful conditionals • Loops and iterators
  30. 30. Example templates • ApacheVirtualHost configuration file • HAProxy configuration • …
  31. 31. Rollback? • http://www.servermanaged.it/ansible/ansible-simple- rollback-strategy/ • http://www.future500.nl/articles/2014/07/thoughts- on-deploying-with-ansible/
  32. 32. Resources • http://docs.ansible.com/ • http://docs.ansible.com/ playbooks_best_practices.html • https://galaxy.ansible.com/ • https://github.com/ansible/ansible-examples • https://github.com/leucos/ansible-tuto
  33. 33. Books
  34. 34. Real world app 1 app 2 app 3 DB - master DB - slave RabbitMQ Redisapp 4 storage transcoder logs monitoring
  35. 35. Questions? • Igor Brovchenko • @tigordev • igor.Brovchenko@gmail.com • http://ua.linkedin.com/in/IgorBrovchenko

×