$30 off During Our Annual Pro Sale. View Details »

Managing Modern Infrastructure with Ansible

Managing Modern Infrastructure with Ansible

Joe Ferguson

October 24, 2019
Tweet

More Decks by Joe Ferguson

Other Decks in Programming

Transcript

  1. Managing Modern
    Infrastructure with Ansible
    Joe Ferguson
    https://github.com/svpernova09/ModernInfrastructureWithAnsible

    View Slide

  2. Who Am I?
    Joe Ferguson
    PHP Developer
    Senior Full Stack Dev @ Preteckt
    Open Source Geek
    ⚽,, and fan
    Twitter: @JoePFerguson

    View Slide

  3. Ansible for DevOps
    https://leanpub.com/ansible-for-devops

    View Slide

  4. View Slide

  5. pip install ansible

    View Slide

  6. Ansible Concepts
    Modules
    Standalone work units to perform a task
    Inventory Configuration
    Declaration of target systems to perform tasks upon
    Playbooks
    Complete set of roles / list of actions to take

    View Slide

  7. Command Module

    View Slide

  8. Command Module

    View Slide

  9. Command Module

    View Slide

  10. Create Ansible Playbook

    View Slide

  11. Running Our Ansible Playbook

    View Slide

  12. Ansible Variable Precedence
    http://docs.ansible.com/ansible/playbooks_variables.html

    View Slide

  13. Ansible Variable Precedence
    • command line values (eg “-u user”)
    • role defaults
    • inventory file or script group vars
    • inventory group_vars/all
    • playbook group_vars/all
    • inventory group_vars/*
    • playbook group_vars/*
    • inventory file or script host vars

    View Slide

  14. Reusing Playbooks from others

    View Slide

  15. Ansible Galaxy Authors

    View Slide

  16. Adding geerlingguy.php

    View Slide

  17. Overriding Variables

    View Slide

  18. Overriding Variables

    View Slide

  19. Adding ansible-role-php

    View Slide

  20. Adding ansible-role-php

    View Slide

  21. Running ansible-role-php

    View Slide

  22. Production Inventory

    View Slide

  23. Staging Inventory

    View Slide

  24. Dev Inventory

    View Slide

  25. ansible_playbook -i prod.ini
    ansible_playbook -i staging.ini
    ansible_playbook -i dev.ini

    View Slide

  26. Ansible can deploy your code

    View Slide

  27. General Ansible Advice
    Use environment based playbooks & inventory files for clear
    separation & to easily handle one off differences
    Use Python or some other environment variable system for
    managing your secrets!
    Couple variables to the most focused point, then raise their scope
    as you need

    View Slide

  28. Ansible Tower
    https://www.ansible.com/products/tower

    View Slide

  29. Ansible Tower
    https://www.ansible.com/products/tower/pricing

    View Slide

  30. AWX - Open Source Tower

    View Slide

  31. AWX - Open Source Tower

    View Slide

  32. Python for PHP Devs
    Python
    PHP
    Composer
    Packagist
    composer.json
    FPM
    ???
    composer.lock
    Pip
    PyPi & Others
    requirements.txt
    WSGI
    VirtualEnv
    LOL lock files

    View Slide

  33. Virtual Environments

    View Slide

  34. Install Dependencies

    View Slide

  35. Install Dependencies

    View Slide

  36. Freeze Dependencies

    View Slide

  37. Our Virtual Env

    View Slide

  38. Building a Deploy Playbook
    http://vcdt.joeferguson.me/

    View Slide

  39. Playbook File

    View Slide

  40. deploy-vcdt-app Role

    View Slide

  41. deploy-vcdt-app Role

    View Slide

  42. Using Jinja2 Templates

    View Slide

  43. Update the Repository

    View Slide

  44. Composer Install

    View Slide

  45. Application Setup

    View Slide

  46. Job’s Done!

    View Slide

  47. Break Up Large YAML

    View Slide

  48. System Maintenance

    View Slide

  49. System Maintenance

    View Slide

  50. Install & Configure Certbot

    View Slide

  51. Create SSL & Cron

    View Slide

  52. Combine SSL For HAProxy

    View Slide

  53. Delayed Service Restarting

    View Slide

  54. Renewal Post Hook Script

    View Slide

  55. Renewal Post Hook Script

    View Slide

  56. Install Docker

    View Slide

  57. Install Docker

    View Slide

  58. Add Users

    View Slide

  59. Looping over Arrays (Hashes)

    View Slide

  60. Directory Layout

    View Slide

  61. Directory Layout

    View Slide

  62. Directory Layout

    View Slide

  63. Keep Your Secrets Secret!

    View Slide

  64. Rolling Updates: Serial

    View Slide

  65. Maximum Failure

    View Slide

  66. Joe Ferguson
    Twitter: @JoePFerguson
    Email: [email protected]
    Contact Info:
    Thanks!

    View Slide