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

Introduction to Ansible

Introduction to Ansible

Vincent Roy: Introduction to Ansible
Ansible is automation for everyone. Ansible seamlessly unites workflow orchestration with configuration management, provisioning, and application deployment in one easy-to-use and deploy platform.

Regardless of where you start with Ansible, you’ll find our simple, powerful and agentless automation platform has the capabilities to solve your most challenging problems.

In this talk, Vincent will cover the basics of Ansible and demonstrate how it can be used to manage a simple webserver and how it can be used to deploy the monctonug.net site.

Vincent Roy is a full stack software developer with just under 10 years of experience. In that time he's had a chance to work with various technologies from backend services written in Ruby on Rails to browser applications written using CoffeeScript.

He is currently a Senior Software Engineer at EMC writing backend and infrastructure services in Java, Python, JavaScript and Go.

Moncton Developer User Group

September 20, 2016
Tweet

More Decks by Moncton Developer User Group

Other Decks in Programming

Transcript

  1. Ansible is automation for everyone. Ansible seamlessly unites workflow orchestration

    with configuration management, provisioning, and application deployment in one easy-to-use and deploy platform. Regardless of where you start with Ansible, you’ll find our simple, powerful and agentless automation platform has the capabilities to solve your most challenging problems. ansible.com COMPLETE IT AUTOMATION
  2. WHY ANSIBLE? USE CASES ▸ Provisioning ▸ Configuration Management ▸

    App Deployment ▸ Continuous Delivery ▸ Security & Compliance ▸ Orchestration
  3. WHY ANSIBLE? INTEGRATIONS: INFRASTRUCTURE ▸ Bare metal ▸ Cobbler, Stacki,

    RackHD, … ▸ Virtualization ▸ VMware, Red Hat Enterprise Virtualization (RHEV), Libvirt, Xenserver, Vagrant ▸ Operating systems ▸ Linux, Windows, OS X
  4. WHY ANSIBLE? INTEGRATIONS: CLOUD ▸ AWS ▸ Google Cloud ▸

    Digital Ocean ▸ Linode ▸ OpenStack
  5. WHY ANSIBLE? INTEGRATIONS: DEVOPS TOOLS ▸ Source Control ▸ Monitoring

    ▸ Chat ▸ Analytics ▸ Testing & Continuous Integration
  6. WHY ANSIBLE? MISC. ▸ Secure (SSH) ▸ Agentless ▸ Source

    control your infrastructure ▸ Minimal dependencies
  7. HOW? INVENTORY [webservers] web1.example.com web2.example.com [webservers:vars] load_balancer=lb1.example.com [lbservers] lb1.example.com [dbservers]

    db1.example.com db2.example.com slave=true [ruby] web1.example.com web2.example.com lb1.example.com [east] web1.example.com db1.example.com lb1.example.com [west] web2.example.com db2.example.com
  8. HOW? INVENTORY [webservers] web1.example.com web2.example.com [webservers:vars] load_balancer=lb1.example.com [lbservers] lb1.example.com [dbservers]

    db1.example.com db2.example.com slave=true [ruby] web1.example.com web2.example.com lb1.example.com [east] web1.example.com db1.example.com lb1.example.com [west] web2.example.com db2.example.com ALL RUBY WEBSERVERS web1.example.com web2.example.com LBSERVERS lb1.example.com DBSERVERS db1.example.com db2.example.com EAST web1.example.com db1.example.com lb1.example.com WEST web2.example.com db2.example.com
  9. HOW? DYNAMIC INVENTORY ▸ Executable that returns JSON ▸ AWS

    ▸ OpenStack ▸ Google Compute Engine ▸ DigitalOcean ▸ and more community contributed executables
  10. HOW? DYNAMIC INVENTORY { "all" : { "hosts" : [

    "web1.example.com", "web2.example.com", "lb1.example.com", "db1.example.com", "db2.example.com" ], "vars" : { "load_balancer": "lb1.example.com" } }, "_meta" : { "hostvars" : { "db2.example.com": { "slave": "true" } } }, "webservers": { "hosts": [ "web1.example.com", "web2.example.com" ] }, "lbservers": { "hosts": [ "lb1.example.com" ] }, "dbservers": { "hosts": [ "db1.example.com", "db2.example.com" ] }, "ruby": { "hosts": [ "web1.example.com", "web2.example.com", "lb1.example.com" ] }, "east": { "hosts": [ "web1.example.com", "db1.example.com", "lb1.example.com" ] }, "west": { "hosts": [ "web2.example.com", "db2.example.com" ] } }
  11. HOW? PLAYBOOKS ▸ Expressed in YAML ▸ Jinja2 templates ▸

    A playbook is a list of plays ▸ A play maps a group of hosts to roles or tasks ▸ A task is a call to an ansible module
  12. HOW? PLAYBOOK EXAMPLE - hosts: webservers vars: http_port: 80 max_clients:

    200 tasks: - name: ensure nginx is at the latest version apt: name=nginx state=latest - name: write the nginx config file template: src=/srv/nginx.conf.j2 dest=/etc/nginx/nginx.conf - name: restart nginx service: name: nginx state: restarted - name: ensure nginx is running (and enable it at boot) service: name=nginx state=started enabled=yes
  13. HOW? MODULES ▸ Modules are [generally] idempotent ▸ Executes on

    the targeted hosts ▸ Hundreds of core and community contributed modules ▸ Write your own ▸ http://docs.ansible.com/ansible/list_of_all_modules.html
  14. DEMO DEPLOYING THE MONCTONUG WEBSITE ▸ Create a Digital Ocean

    droplet ▸ Install dependencies required for building site ▸ Configure authorization keys for accessing GitHub and Eventbrite ▸ Build site ▸ Configure nginx
  15. DIRECTORY STRUCTURE . ├── ansible.cfg ├── build.yml ├── configure-webserver.yml ├──

    group_vars │ ├── all │ │ ├── secrets.ml ** encrypted with ansible-vault ** │ │ └── vars.yml │ └── webservers.yml ├── inventory │ └── digital_ocean.py ├── roles │ ├── build-monctonug │ │ └── tasks │ │ └── main.yml │ │ └── templates │ │ └── dotenv │ ├── configure-git │ │ └── tasks │ │ └── main.yml │ └── configure-nginx │ ├── defaults │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ ├── default.conf.j2 │ └── monctonug.conf.j2 └── run DEMO