We need to talk about provisioning – Vars



We need to talk about provisioning – Vars

0 0


talk-ansible

Ansible talk in RevealJS

On Github skinofstars / talk-ansible

We need to talk about provisioning

by Kevin

skinofstars

What is provisioning?

Installing packages

Configuration

What is deployment?

Updating app code

Servers are cattle, not pets

Can you remember everything you did to set up a server?

  • Installs, updates, version pinning
  • Ruby install
  • Database setup
  • Nginx config
  • Service monitoring
  • Logging
  • Sendmail...
  • Timezones?!

Repeatable setups, anywhere

Vagrant

Any old server set-up

Cloud instances management

Workbox set-up

OK OK! What shall I use then?

SOMETHING!!!

Chef

Puppet

Salt

Ansible

Ansible...

Uses Python, so pretty universal

Uses SSH, so no installing on remote systems

Scripting with YAML, so even an idiot can use it

Getting set up

apt-get

  apt-get install ansible
        

pip

  easy_install pip
  pip install ansible
        

source

  easy_install pip
  pip install pyyaml jinja2 nose passlib pycrypto
  git clone git@github.com:ansible/ansible.git
  source ./hacking/env-setup
        

Defining your servers

INI format host files

default - /etc/ansible/hosts

  [appservers]
  192.168.1.23
  192.168.1.99
        

or

  [myapp:children]
  appservers
  dbservers

  [appservers]
  pedrosa.example.com ansible_ssh_user=dani
  lorenzo.example.com ansible_ssh_user=jorge

  [dbservers]
  db-[a:f].example.com
        

ad-hoc commands

  ansible appservers -m copy -a "src=/etc/hosts dest=/tmp/hosts"
      

I NEVER DO THIS!!!1!

Playbooks

I ALWAYS DO THIS!!!2!

  ---
  # playbook.yml

  - hosts: appservers
    tasks:
      - name: Super secure secret sharing stuff
        copy: src=secrets.txt dest=/srv/public/secrets.txt mode=777
        
  ansible-playbook appservers playbook.yml
        

Vars

  ---
  # playbook
  - hosts: all
    vars:
      my_common_packages:
        - curl
        - git
    tasks:
      - name: Install some stuff
        apt: pkg={{ item }} state=present
        with_items: my_common_packages
        

There are also a lot of built in variables, like

{{ ansible_pkg_mgr }}

  - name: Install some stuff on Debian
    apt: pkg={{ item }} state=present
    with_items:
      - curl
      - git
    when: ansible_pkg_mgr == "apt"
        

Modules

There are loads

Common tasks like apt, git, pg/mysql/redis... or shell scripts

Services like AWS, Linode, etc

Templates

Uses jinja2


  ---
  # playbook.yml

  - hosts: all
    vars_prompt:
      name: "What is your name?"
      loot: "Where is the money?"
    tasks:
      - name: Super secure secret sharing stuff
        copy: src=secrets.txt dest=/srv/public/secrets.txt mode=777

      
        # secrets.txt
        My name is {{ name }}
        The cash is at {{ loot }}
      

Roles and best practice

  staging.yml
  production.yml
      
  /roles
    /nginx
      /handlers
        main.yml
      /tasks
        main.yml
      /templates
        nginx.conf
      /vars
        main.yml
      

Resources

docs - docs.ansible.com

ansible-examples - github.com/ansible/ansible-examples

Galaxy - galaxy.ansible.com

Tower - ansible.com/tower

fin