Slide 1

Slide 1 text

Igor Brovchenko Let's Get Acquainted:

Slide 2

Slide 2 text

About me • Engineer • Chief Software Engineer at Swivl • Symfony Camp UA Igor Brovchenko [email protected] @tigordev

Slide 3

Slide 3 text

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)

Slide 4

Slide 4 text

Use cases • Server provisioning • Server orchestration • Application deployment • Continues Integration • …

Slide 5

Slide 5 text

Who uses Ansible? Over 1 Million Downloads Over 900 contributors and 8000 ★s on GitHub

Slide 6

Slide 6 text

Other tools • fabric • capistrano (capifony) • puppet • chef • saltstack

Slide 7

Slide 7 text

Ansible 1.7.2 • Development - 1.8 • A new major release of Ansible approximately every 2 months.

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Managed Node Requirements • Python 2.4 • Starting in version 1.7, Ansible contains support for managing Windows machines

Slide 10

Slide 10 text

https://galaxy.ansible.com/

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

http://www.ansible.com/tower

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

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…

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Directory Structure `-- /var/www/example.com |-- current → /var/www/example.com/releases/20141012131539 |-- releases | `-- 20141012131539 | `-- 20141009150741 | `-- 20141031145325 `-- shared |-- web | `-- uploads |-- logs `-- config `-- parameters.yml

Slide 17

Slide 17 text

Installing the Control Machine (Mac OSX) $ brew update $ brew install ansible $ ansible-galaxy install servergrove.symfony2

Slide 18

Slide 18 text

Installing the Control Machine (Mac OSX) $ ls /usr/local/etc/ansible hosts roles $ ls /usr/local/etc/ansible/hosts/roles servergrove.symfony2

Slide 19

Slide 19 text

Deploy $ ansible-playbook app/config/playbook_deploy.yml $ ansible-playbook -l localhost app/config/playbook_deploy.yml -vvv

Slide 20

Slide 20 text

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: [email protected]: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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Inventory (hosts) $ ansible localhost -m command "echo \"Hello World\" " $ ansible prod-app -m ping

Slide 23

Slide 23 text

Ansible Structure • Inventory • Modules • Ad Hoc Commands • Playbooks • Tasks • Variables • Templates • Handlers • Roles

Slide 24

Slide 24 text

Modules • Cloud • Commands • Database • Files • Internal • Inventory • Messaging • Monitoring • Net Infrastructure • Network • Notification • Packaging • Source Control • System • Utilities • Web Infrastructure • Windows

Slide 25

Slide 25 text

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 • …

Slide 26

Slide 26 text

Notification Modules • flowdock • hipchat • irc • jabber • slac • sns • twilio • …

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

http://docs.ansible.com/guide_vagrant.html

Slide 29

Slide 29 text

Roles • YAML • Documentation • Modules (task) • Ansible Galaxy

Slide 30

Slide 30 text

Tasks (main.yml)

Slide 31

Slide 31 text

Templates • Templates are processed by the Jinja2 templating language (http://jinja.pocoo.org/docs/dev/templates/) • Powerful conditionals • Loops and iterators

Slide 32

Slide 32 text

Example templates • Apache VirtualHost configuration file • HAProxy configuration • …

Slide 33

Slide 33 text

Rollback? • http://www.servermanaged.it/ansible/ansible-simple- rollback-strategy/ • http://www.future500.nl/articles/2014/07/thoughts- on-deploying-with-ansible/

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Books

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Real world app 1 app 2 app 3 DB - master DB - slave RabbitMQ Redis app 4 storage transcoder logs monitoring

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Questions? • Igor Brovchenko • @tigordev • [email protected] • http://ua.linkedin.com/in/IgorBrovchenko