What is it?

  • Configuration Management
  • Provisioning Hosts

Run Commands

$ ansible all -m ping
162.243.233.104 | success >> {
    "changed": false,
    "ping": "pong"
}

$ ansible all -a "/bin/hostname"                                                                                                                                             master * ] 2:15 PM
162.243.233.104 | success | rc=0 >>
ubuntu-512mb-nyc2-01

Hosts

Static hosts

  • INI style format
[webservers]
162.243.233.104

Dynamic Hosts

  • Allow querys for hosts
  • Support for AWS, Digital Ocean, etc.

Playbooks

Properties

  • Knows facts on system
  • Idempotent
  • List of tasks to run

Title Text

- hosts: observatory
  remote_user: root
  gather_facts: false
  vars:
    - log_file: "/opt/observatory.log"
    - server_dir: "/opt/Observatory3/"
    - port: 8443
  tasks:
    - git:
        repo='https://github.com/rcos/Observatory3.git'
        version="{{ release }}"
        dest="{{ server_dir }}"

    - command: /usr/local/bin/npm install
      args:
        chdir: "{{ server_dir }}"

    - command: /usr/local/bin/grunt build --force
      args:
        chdir: "{{ server_dir }}"

    - shell: "NODE_ENV=production PORT={{ port }} forever -a -l {{ log_file }} start {{ server_dir }}dist/server/app.js"

Configuring hosts

  • Vars
  • Tasks
  • Handlers

Roles

Directory Layout

   webservers/
     files/
     templates/
     tasks/
     handlers/
     vars/
     defaults/
     meta/

Goal: Reusability

  • Common tasks and variables
  • Example:
    • nginx
    • php
    • etc
  • Modular

When to use

  • Launching servers
  • Initializing Systems
  • Updating applications

Demo?