Skip to content

Instantly share code, notes, and snippets.

@finchd
Created November 13, 2018 06:48
Show Gist options
  • Save finchd/d6e04a15e20b7207a066328e3c24a7bb to your computer and use it in GitHub Desktop.
Save finchd/d6e04a15e20b7207a066328e3c24a7bb to your computer and use it in GitHub Desktop.
SeaGL 2018 - Structured Ansible Playbooks

Structured Ansible Playbooks

Sasha Reid (sasha at- hackl.es) @microwavenby

Just use the PDF of slides: https://bit.do/seagl_ansible https://d.pr/f/Nguxgt

sample flat playbook

create dir

- name:
  file:

clone git repo

- name:
  git:

virtualenv

- name:
  become: no
  pip:
    requirements:

install supervisord

- name:
  apt:
    name: supervisor
    state: latest
- name:
  template:
    src:
    dest:

start app

  • it works
  • a second one look svery similar and duplicate....

roles & variables

  • ansible prioritization of variables is confusing
  • roles allow to segment into the required sub-folders
  • folders auto-detect main.yml into the folders
  • don't duplicate all of the playbook

defaults

what is the difference between variables & defaults? defaults get overridden first, bottom of precedence

basically:

  1. group_vars
  2. host_vars
  3. host facts
  4. play vars
  5. role vars
  6. block vars
  7. task vars
  8. cli vars
  • setting defaults sets documentation of sane

make a role

  • make important values into vars

  • "role inheritence", make much more generic

  • then a "sub-role" that just consumes the generic one!

    • don't set defaults in the sub-role, they smash the meta-role ones
  • roles in /meta/ get executed first before /tasks/, and in order

  • pass full paths to your meta-roles - they don't get operated in the sub-role context

  • only need include_role: tasks for much more control, running multiple times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment