Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

Let's Get Acquainted: Ansible!

Igor Brovchenko

November 03, 2014
Tweet

More Decks by Igor Brovchenko

Other Decks in Programming

Transcript

  1. 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)
  2. Ansible 1.7.2 • Development - 1.8 • A new major

    release of Ansible approximately every 2 months.
  3. 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
  4. Managed Node Requirements • Python 2.4 • Starting in version

    1.7, Ansible contains support for managing Windows machines
  5. 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…
  6. 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
  7. Directory Structure `-- /var/www/example.com |-- current → /var/www/example.com/releases/20141012131539 |-- releases

    | `-- 20141012131539 | `-- 20141009150741 | `-- 20141031145325 `-- shared |-- web | `-- uploads |-- logs `-- config `-- parameters.yml
  8. Installing the Control Machine (Mac OSX) $ brew update $

    brew install ansible $ ansible-galaxy install servergrove.symfony2
  9. Installing the Control Machine (Mac OSX) $ ls /usr/local/etc/ansible hosts

    roles $ ls /usr/local/etc/ansible/hosts/roles servergrove.symfony2
  10. 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
  11. Ansible Structure • Inventory • Modules • Ad Hoc Commands

    • Playbooks • Tasks • Variables • Templates • Handlers • Roles
  12. Modules • Cloud • Commands • Database • Files •

    Internal • Inventory • Messaging • Monitoring • Net Infrastructure • Network • Notification • Packaging • Source Control • System • Utilities • Web Infrastructure • Windows
  13. 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 • …
  14. 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
  15. Templates • Templates are processed by the Jinja2 templating language

    (http://jinja.pocoo.org/docs/dev/templates/) • Powerful conditionals • Loops and iterators
  16. Real world app 1 app 2 app 3 DB -

    master DB - slave RabbitMQ Redis app 4 storage transcoder logs monitoring