automated deployments

107
1 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014 Orlando, October 2014 Automated Deployments – Hands- On Martin Etmajer [email protected] Senior Technology Strategist @ Dynatrace

Upload: martin-etmajer

Post on 12-Jun-2015

728 views

Category:

Software


0 download

DESCRIPTION

Shows an excerpt of the PERFORM 2014 Conference's Hands-On Training on Automated Deployments. Tells the why and the how and differentiates between agent-based and agentless solutions, such as Chef, Puppet or Ansible. Goes into greater detail on the Ansible host automation tool.

TRANSCRIPT

Page 1: Automated Deployments

1 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Orlando, October 2014

Automated Deployments – Hands-On Martin Etmajer

[email protected] Technology Strategist @

Dynatrace

Page 2: Automated Deployments

2 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Insert headshot image here “Martin Etmajer

Senior Technology Strategist @ Dynatrace

[email protected]

@metmajer

Page 3: Automated Deployments

3 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

From Continuous Integration toContinuous Delivery

Page 4: Automated Deployments

4 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Integration

Page 5: Automated Deployments

5 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Integration

Page 6: Automated Deployments

6 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Integration

Page 7: Automated Deployments

7 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Integration

Page 8: Automated Deployments

8 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 9: Automated Deployments

9 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 10: Automated Deployments

10 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 11: Automated Deployments

11 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 12: Automated Deployments

12 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 13: Automated Deployments

13 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

Page 14: Automated Deployments

14 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

✔ ✔

Page 15: Automated Deployments

15 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

✔ ✔

Page 16: Automated Deployments

16 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

✔ ✔ ✔

Page 17: Automated Deployments

17 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

✔ ✔ ✔

Page 18: Automated Deployments

18 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Continuous Delivery Build Pipeline

✔ ✔ ✔

Page 19: Automated Deployments

19 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Introduction toAutomated Deployments

Page 20: Automated Deployments

20 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Motivation

Production environments are often grown “works of art”:

» Not entirely reproducible

» Manual changes applied whenever needed

» Not even similar to the environments developers have

“Works on my machine.”

Page 21: Automated Deployments

21 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Automation

Page 22: Automated Deployments

22 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Makes provisioning a repeatable, low-risk “push-button” activity

» By providing executable specifications

» No manual changes involved (regarded immutable)

» The process is tested with each execution (builds confidence)

Benefits: Automation

RecreateEnvironments

Page 23: Automated Deployments

23 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Makes provisioning an engineering discipline:

» Iteratively plan, code, test and verify

» Open to frequently changing requirements (agile)

Helps align efforts between Development and Operations:

» Jointly define desired environmental states

» Integrate and respect each others processes

Benefits: Automation

Page 24: Automated Deployments

24 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

OPERATIONS

DEVELOPMENT

Benefits: Automation

current iteration(2 weeks)

time

Planning

Implementand test Verification

Page 25: Automated Deployments

25 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Automation

Allows the provisioning process to be integrated into the Continuous Delivery build pipeline (build automation server):

» Environments can be provisioned multiple times a day

» When the process fails in staging, the release candidate is discarded - the production environment will not be harmed

Page 26: Automated Deployments

26 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Automation

Reduces the risks of software releases by providing a consistent process for all staging and production environments

Risks?

» Differing library versions

» Differing middleware configurations

» Differing environmental variables in the OS

» Differing number of max. open file handles in the OS,…

Page 27: Automated Deployments

27 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Auditability

Page 28: Automated Deployments

28 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Auditability

What, who, why and when?

» Keep all (executable) specifications in VCS

» Provide meaningful commit messages (changelog)

» Build history tells you which revision got deployed

“Infrastructure as Code”

Page 29: Automated Deployments

29 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Repeatability

Page 30: Automated Deployments

30 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Repeatability

Establishes a process that is repeatable at any time:

» Environments are no longer in the hands of single people

» Any (authorized) person could recreate the environments

» Requires command execution to be idempotent

Page 31: Automated Deployments

31 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Benefits: Repeatability

Allows for testability of the deployment process:

» Failures will be caught early-on in the process

What if something breaks?

» Caught a bug: use a version that is known to work

» Hardware failure: redeploy environment in minutes

Minimizes MTTR

Page 32: Automated Deployments

32 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Deployment Automation Solutions:Agent-based vs. Agentless

Page 33: Automated Deployments

33 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Solutions

Page 34: Automated Deployments

34 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Deployments (Chef, Puppet)

Page 35: Automated Deployments

35 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Deployments (Chef, Puppet)

Page 36: Automated Deployments

36 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Deployments (Chef, Puppet)

Page 37: Automated Deployments

37 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Deployments (Chef, Puppet)

» Can be used in client-server or client-only modes

» Client must be installed on each host to be provisioned

» Clients have dependencies: Ruby

Page 38: Automated Deployments

38 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agent-Based Deployments

Puppet

» Written and extensible in Ruby (comes with a DSL)

» Order of statement does not specify order of execution

» Huge ecosystem (PuppetDB, MCollective, Hiera)

» Large entrance barrier

Page 39: Automated Deployments

39 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agentless Solutions

Page 40: Automated Deployments

40 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agentless Deployments (Ansible)

Page 41: Automated Deployments

41 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agentless Deployments (Ansible)

Page 42: Automated Deployments

42 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agentless Deployments (Ansible)

Page 43: Automated Deployments

43 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Agentless Deployments (Ansible)

Page 44: Automated Deployments

44 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible

» Written and extensible (Python)

» Human- and machine-readable configuration (YAML)

» No boot-strapping required on deployment hosts (SSH)

» Simple, easy to ramp up with (think of new employees!)

» Clear and concise documentation

Agentless Deployments

Page 45: Automated Deployments

45 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Hands-On Training: Environment

Page 46: Automated Deployments

46 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Sample Environment

Web Server

Frontend

Application Server

Backend

Application ServerDatabase

VCS Build Automation

check out deploy

Page 47: Automated Deployments

47 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Sample Environment

Web Server FrontendApplication Server

BackendApplication Server

Database

Apache Tomcat Apache TomcatApache PostgreSQL

VCS

Git

Build Automation

Jenkins

check out deploy

Page 48: Automated Deployments

48 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Use Case: Deploy Dynatrace Agents

Web Server FrontendApplication Server

BackendApplication Server

Database

Apache Tomcat Apache TomcatApache PostgreSQL

VCS

Git

Build Automation

Jenkins

check out deploy

Page 49: Automated Deployments

49 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Use Case: Deploy Dynatrace Agents

Web Server FrontendApplication Server

BackendApplication Server

Database

Apache Tomcat Apache TomcatApache PostgreSQL

VCS

Git

Build Automation

Jenkins

check out deploy

Dynatrace Server

Page 50: Automated Deployments

50 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Hands-On Training: Environment

Page 51: Automated Deployments

51 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

1. Inject dynaTrace Agents into Apache Tomcats

2. Load database data into PostgreSQL

3. Integrate all this into Jenkins

Today you will learn how to automatically...

Page 52: Automated Deployments

52 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible: Core Concepts

Page 53: Automated Deployments

53 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts:Inventories

Page 54: Automated Deployments

54 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Inventories

» Ansible provisions groups of servers at once

» Groups and hosts are stored in inventory files

» An inventory file is expressed in a simple INI format

» Default location: /etc/ansible/hosts

» bit.ly/ansible-inventory

Page 55: Automated Deployments

55 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Inventories

[frontends]frontend.example.com

[backends]backend.example.com

[frontends:vars]dt_agent_name=frontend

[backends:vars]dt_agent_name=backend

GroupHost

GroupVariables Variable

Page 56: Automated Deployments

56 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts:Ad-hoc Commands

Page 57: Automated Deployments

57 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Ad-hoc Commands

ansible <host-pattern> [options]

Examples?

» ansible localhost -m copy –a ‘src=/usr/bin/a dest=/usr/bin/b’

» ansible appservers –a ‘/sbin/reboot’ –f 10

» ansible appservers –a ‘/sbin/reboot’ –f 10–u deploy ––sudo ––ask–sudo–pass

Module Arguments

Page 58: Automated Deployments

58 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Ad-hoc Commands

ansible <host-pattern> [options]

Examples?

» ansible localhost -m copy –a ‘src=/usr/bin/a dest=/usr/bin/b’

» ansible appservers –a ‘/sbin/reboot’ –f 10

» ansible appservers –a ‘/sbin/reboot’ –f 10–u deploy ––sudo ––ask–sudo–pass

Forks

Page 59: Automated Deployments

59 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Ad-hoc Commands

ansible <host-pattern> [options]

Examples?

» ansible localhost -m copy –a ‘src=/usr/bin/a dest=/usr/bin/b’

» ansible appservers –a ‘/sbin/reboot’ –f 10

» ansible appservers –a ‘/sbin/reboot’ –f 10–u deploy ––sudo ––ask–sudo–pass

User Use sudoAsk passwordinteractively

Page 60: Automated Deployments

60 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks

Page 61: Automated Deployments

61 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks

ansible-playbook [–i <inventory>] <playbook>

Playbooks

» Describe policies your remote systems shall enforce

» Consist of variables, tasks, handlers, files and roles

» Are expressed in the YAML format

» bit.ly/ansible-playbook

Page 62: Automated Deployments

62 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

YAML (YAML Ain’t No Markup Language): Motivation

» “All data structures can be expressed via dicts, lists and scalars”

» Simplicity makes it much easier to read and parse than XML

Excursion to YAML

Page 63: Automated Deployments

63 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Blockname: Michael Jordanage: 34

YAML Excursion » Dictionaries

--- # Inline{ name: Michael Jordan, age: 34 }

Page 64: Automated Deployments

64 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Blockname: Michael Jordanage: 34

YAML Excursion » Dictionaries

--- # Inline{ name: Michael Jordan, age: 34 }

Document

Page 65: Automated Deployments

65 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Blockname: Michael Jordanage: 34

YAML Excursion » Dictionaries

--- # Inline{ name: Michael Jordan, age: 34 }

key: value

SameIndentation

level

Page 66: Automated Deployments

66 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Blockname: Michael Jordanage: 34

YAML Excursion » Dictionaries

--- # Inline{ name: Michael Jordan, age: 34 }

Comment

Optional quotesfor Strings

Page 67: Automated Deployments

67 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Block- milk- bread- butter

YAML Excursion » Lists

--- # Inline[milk, bread, butter]

Page 68: Automated Deployments

68 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Block- milk- bread- butter

YAML Excursion » Lists

--- # Inline[milk, bread, butter]

Items start withhyphen + space

Page 69: Automated Deployments

69 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # Block- milk- bread- butter

YAML Excursion » Lists

--- # Inline[milk, bread, butter]Same

indentationlevel

Page 70: Automated Deployments

70 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

---men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 }women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 }

YAML Excursion » Complex

Page 71: Automated Deployments

71 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

---men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 }women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 }

YAML Excursion » Complex

Dictionary

List

Page 72: Automated Deployments

72 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

---men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 }women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 }

YAML Excursion » Complex

List

Dictionary

Page 73: Automated Deployments

73 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # appservers.yml- hosts: frontends:backends vars_files: - variables.yml handlers: - name: restart tomcat service: name=tomcat state=restarted tasks: - name: Inject dynaTrace Java agent into Apache Tomcat template: > src=templates/tomcat-setenv.sh dest={{ tomcat_home }}/bin/setenv.sh notify: restart tomcat remote_user: deploy sudo: yes

Ansible Concepts: Playbooks

Play

Page 74: Automated Deployments

74 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks

# production

[frontends]frontend.example.com

[backends]backend.example.com

[frontends:vars]dt_agent_name=frontend

[backends:vars]dt_agent_name=backend

Page 75: Automated Deployments

75 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks

# templates/tomcat-setenv.sh

CATALINA_OPTS="$CATALINA_OPTS \ -agentpath:{{ dt_agent_dir }}/libdtagent.so =name={{ dt_agent_name }},collector={{ dt_collector_url }}"

Page 76: Automated Deployments

76 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # variables.ymltomcat_home: /opt/tomcatdt_agent_dir: /opt/dynatrace/agentsdt_collector_url: dynatrace.example.com

Ansible Concepts: Playbooks

Page 77: Automated Deployments

77 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks

ansible-playbook –i production appservers.yml

PLAY [frontends:backends] ******************************************************

TASK: [Inject dynaTrace Java agent into Apache Tomcat] ************************ changed: [backend.example.com]changed: [frontend.example.com]

PLAY RECAP ************************************************************************backend.example.com : ok=1 changed=1 unreachable=0 failed=0 frontend.example.com : ok=1 changed=1 unreachable=0 failed=0

Run!

Page 78: Automated Deployments

78 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # playbook.yml- include: appservers.yml- include: dbservers.yml- include: webservers.yml

Ansible Concepts: Playbooks

Includes multiple playsinto a single playbook

Page 79: Automated Deployments

79 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Usage

» {{ foo }}

» {{ foo[i] }}

» {{ foo.bar }}

» Hello, my name is {{ foo }}

» bit.ly/ansible-variables

Page 80: Automated Deployments

80 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variables

Page 81: Automated Deployments

81 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variables

Forces ‘foo’ to be defined

Page 82: Automated Deployments

82 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variables

Defaults ‘foo’ to 0 if undefined

Page 83: Automated Deployments

83 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variables

Computes the minimum in ‘list’

Page 84: Automated Deployments

84 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variables

Computes distinct values in ‘list’

Page 85: Automated Deployments

85 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Advance Usage

» {{ foo | mandatory }}

» {{ foo | default(0) }}

» {{ list| min }}

» {{ list| unique }}

» {{ list1 | union(list2) }}

» bit.ly/ansible-variablesComputes a join of lists ‘list1 and ‘list2’

Page 86: Automated Deployments

86 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

Validity

» Valid: ‘foo_bar’, ‘foo5’

» Invalid: ‘foo-bar’, ‘foo bar’, ‘foo.bar’, ‘5foo’, ‘5’

Page 87: Automated Deployments

87 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

--- # playbook.yml- hosts: all vars: - cleanup_home: yes - settings: ports: http: 80 ssl: 443 …

Inlined

Page 88: Automated Deployments

88 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Variables

--- # playbook.yml- hosts: all vars_files: - variables.yml …

--- # variables.ymlcleanup_home: yessettings: ports: http: 80 ssl: 443

Imported

Page 89: Automated Deployments

89 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # playbook.yml- hosts: all tasks: - { include: create-user.yml, user: deploy }…

Ansible Concepts: Playbooks » Variables

Defined intask inclusion

Page 90: Automated Deployments

90 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

--- # playbook.yml- hosts: all roles: - { role: create-user, user: deploy }…

Ansible Concepts: Playbooks » Variables

Defined inrole inclusion

Page 91: Automated Deployments

91 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

ansible –e ‘user=deploy’ playbook.yml

Ansible Concepts: Playbooks » Variables

Defined atinvocation

Page 92: Automated Deployments

92 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Tasks

Tasks are...

» invocations of Ansible modules

» the units that do the actual deployment and configuration

» bit.ly/ansible-module

Page 93: Automated Deployments

93 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Tasks

Example: Install package ‘apache2’

--- # webservers.yml- hosts: webservers tasks: - name: Install package ‘apache2’ apt: pkg=apache2 state=latest update_cache: yes

Page 94: Automated Deployments

94 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Tasks

Example: Copy file from src (localhost) to dest (remote host)

--- # webservers.yml- hosts: webservers tasks: - name: Copy file from ‘foo.conf’ to /etc/default copy: > src=/srv/files/foo.conf dest=/etc/default owner=deploy group=deploy mode=644

Page 95: Automated Deployments

95 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Roles

» Are the preferred means to organize and reuse related tasks

» Build on the idea of include files to form clean abstractions

» bit.ly/ansible-roles

Page 96: Automated Deployments

96 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Reusing Roles in a Play

--- # webservers.yml- hosts: webservers roles: - { role: common } - { role: apache2 } remote_user: deploy sudo: yes

Page 97: Automated Deployments

97 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Top-level Playbook

Page 98: Automated Deployments

98 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Plays

Page 99: Automated Deployments

99 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Holds a role named ‘x’

Page 100: Automated Deployments

100 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Dependencies

Page 101: Automated Deployments

101 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Default variables

Page 102: Automated Deployments

102 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Files

Page 103: Automated Deployments

103 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Handlers

Page 104: Automated Deployments

104 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Tasks

Page 105: Automated Deployments

105 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml Templates

Page 106: Automated Deployments

106 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

Ansible Concepts: Playbooks » Roles

Best Practice: Directory Layout for Role-based Playbooks

playbook.ymlappservers.ymldbservers.ymlwebservers.yml

/roles/x/roles/x/meta/main.yml/roles/x/defaults/main.yml/roles/x/files/roles/x/handlers/main.yml/roles/x/tasks/main.yml/roles/x/templates/main.yml/roles/x/vars/main.yml

Variables

Page 107: Automated Deployments

107 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014