Slide 1

Slide 1 text

10 tips & tricks Sydney Ansible Meetup, Thursday 12 March 2015 Dynamic Clarity

Slide 2

Slide 2 text

define variables with a JSON web service 1

Slide 3

Slide 3 text

{ "server_ip": "192.168.0.44", "server_name": "dilbert" } https://api.site.com/config/staging

Slide 4

Slide 4 text

{ "server_ip": "10.10.11.34", "server_name": "pointy_haired_boss" } https://api.site.com/config/production

Slide 5

Slide 5 text

multi-stage environments 2

Slide 6

Slide 6 text

!"" inventory # !"" _common # # $"" inventory # !"" production # # !"" group_vars # # # $"" all # # !"" host_vars # # $"" inventory -> ../_common/inventory # $"" staging # !"" group_vars # # $"" all # !"" host_vars # $"" inventory -> ../_common/inventory

Slide 7

Slide 7 text

ansible_connection=local for local connections, use 3

Slide 8

Slide 8 text

single self-contained repo 4

Slide 9

Slide 9 text

remove global config
 (/usr/local/etc/ansible/hosts) keep SSH config in Ansible project check out repo and run!

Slide 10

Slide 10 text

cloud-local control host 5

Slide 11

Slide 11 text

co-located on same VPC / VLAN

Slide 12

Slide 12 text

~zero latency no public SSH repo access required

Slide 13

Slide 13 text

buildkite.com* for deployment 6

Slide 14

Slide 14 text

install agent on Ansible control host

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

use roles 7

Slide 17

Slide 17 text

don’t use roles, use include

Slide 18

Slide 18 text

roles can’t strictly be mixed with tasks

Slide 19

Slide 19 text

pre_tasks: - remove host from load balancer pool roles: - rails tasks: - do stuff post_tasks: - return load balancer back to pool

Slide 20

Slide 20 text

pre_tasks: - remove host from load balancer pool tasks: - do stuff - role: nginx - do more other stuff - role: rails post_tasks: - return load balancer back to pool

Slide 21

Slide 21 text

roles/ nginx/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/

Slide 22

Slide 22 text

$ ansible-galaxy init

Slide 23

Slide 23 text

Ruby* modules 8

Slide 24

Slide 24 text

located in /library must be executable task name is file name

Slide 25

Slide 25 text

#!/usr/bin/env ruby # WANT_JSON shebang warning!

Slide 26

Slide 26 text

*any executable that can read a JSON formatted file (input) and returns JSON to stdout (output)

Slide 27

Slide 27 text

instant offline access to documentation 9

Slide 28

Slide 28 text

Dash Alfred +

Slide 29

Slide 29 text

10 style

Slide 30

Slide 30 text

- name: Install Nginx. yum: name=nginx state=installed

Slide 31

Slide 31 text

- name: copy something template: src: "templates/config.j2" dest: "/home/{{ deploy_user }}/config" owner: "{{ deploy_user }}" group: "{{ deploy_user }}" mode: 0755

Slide 32

Slide 32 text

- name: copy something template: > src="templates/config.j2" dest="/home/{{ deploy_user }}/config" owner="{{ deploy_user }}" group="{{ deploy_user }}" mode=0755

Slide 33

Slide 33 text

multiline for single parameter = good

Slide 34

Slide 34 text

- name: decrypt the key on the server sudo_user: "{{ deploy_key_user }}" command: > openssl rsa -in {{ deploy_key_path }}.protected -out {{ deploy_key_path }} -passin pass:{{ deploy_key_secret }}

Slide 35

Slide 35 text

git.io/pK57

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

ansibleworkshop.com

Slide 38

Slide 38 text

Steven Ringo | stevenringo | [email protected] Dynamic Clarity