Ansible

Uses

  • Configuration
  • Deployment
  • Inventory

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

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

Demo Time

Ansible

By Aaron Gunderson

Ansible

Tech talk on Ansible for rcos.io. Sample Ansible repository can be found at https://github.com/agundy/demo_ansible

  • 331
Loading comments...

More from Aaron Gunderson