Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Automated Deployments – Hands-On 
Orlando, October 2014 
Martin Etmajer 
martin.etmajer@dynatrace.com 
Senior Technology S...
image here “ Martin Etmajer 
Insert headshot 
Senior Technology Strategist @ Dynatrace 
martin.etmajer@dynatrace.com 
@met...
From Continuous Integration to 
Continuous Delivery 
3 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Integration 
4 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Integration 
5 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Integration 
6 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Integration 
7 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
8 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
9 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
10 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
11 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ 
12 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ 
13 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ ✔ 
14 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ ✔ 
15 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ ✔ ✔ 
16 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ ✔ ✔ 
17 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Continuous Delivery Build Pipeline 
✔ 
✔ 
✔ ✔ ✔ 
18 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Introduction to 
Automated Deployments 
19 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Motivation 
Production environments are often grown “works of art”: 
» Not entirely reproducible 
» Manual changes applied...
Benefits: Automation 
21 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Benefits: Automation 
Makes provisioning a repeatable, low-risk “push-button” activity 
» By providing executable specific...
Benefits: Automation 
Makes provisioning an engineering discipline: 
» Iteratively plan, code, test and verify 
» Open to ...
Implement 
and test Verification 
DEVELOPMENT 
OPERATIONS 
Benefits: Automation 
current iteration 
(2 weeks) 
time 
Plann...
Benefits: Automation 
Allows the provisioning process to be integrated into the Continuous Delivery build 
pipeline (build...
Benefits: Automation 
Reduces the risks of software releases by providing a consistent process for all staging 
and produc...
Benefits: Auditability 
27 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Benefits: Auditability 
What, who, why and when? 
» Keep all (executable) specifications in VCS 
» Provide meaningful comm...
Benefits: Repeatability 
29 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Benefits: Repeatability 
Establishes a process that is repeatable at any time: 
» Environments are no longer in the hands ...
Benefits: Repeatability 
Allows for testability of the deployment process: 
» Failures will be caught early-on in the proc...
Deployment Automation Solutions: 
Agent-based vs. Agentless 
32 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agent-Based Solutions 
33 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agent-Based Deployments (Chef, Puppet) 
34 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agent-Based Deployments (Chef, Puppet) 
35 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agent-Based Deployments (Chef, Puppet) 
36 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...
Agent-Based Deployments 
Puppet 
» Written and extensible in Ruby (comes with a DSL) 
» Order of statement does not specif...
Agentless Solutions 
39 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agentless Deployments (Ansible) 
40 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agentless Deployments (Ansible) 
41 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agentless Deployments (Ansible) 
42 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agentless Deployments (Ansible) 
43 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Agentless Deployments 
Ansible 
» Written and extensible (Python) 
» Human- and machine-readable configuration (YAML) 
» N...
Hands-On Training: Environment 
45 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Sample Environment 
Web Server Frontend 
Application Server 
Backend 
Application Server 
Database 
check out deploy 
VCS ...
Sample Environment 
Apache Apache Tomcat Apache Tomcat PostgreSQL 
Web Server Frontend 
Application Server 
Backend 
Appli...
Use Case: Deploy Dynatrace Agents 
Apache Apache Tomcat Apache Tomcat PostgreSQL 
Web Server Frontend 
Application Server ...
Use Case: Deploy Dynatrace Agents 
Apache Apache Tomcat Apache Tomcat PostgreSQL 
Web Server Frontend 
Application Server ...
Hands-On Training: Environment 
50 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Today you will learn how to automatically... 
1. Inject dynaTrace Agents into Apache Tomcats 
2. Load database data into P...
Ansible: Core Concepts 
52 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Ansible Concepts: 
Inventories 
53 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Ansible Concepts: Inventories 
» Ansible provisions groups of servers at once 
» Groups and hosts are stored in inventory ...
Ansible Concepts: Inventories 
[frontends] 
frontend.example.com 
[backends] 
backend.example.com 
[frontends:vars] 
dt_ag...
Ansible Concepts: 
Ad-hoc Commands 
56 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Ansible Concepts: Ad-hoc Commands 
ansible <host-pattern> [options] 
Module Arguments 
Examples? 
» ansible localhost -m c...
Ansible Concepts: Ad-hoc Commands 
ansible <host-pattern> [options] 
Examples? 
Forks 
» ansible localhost -m copy –a ‘src...
Ansible Concepts: Ad-hoc Commands 
ansible <host-pattern> [options] 
Examples? 
» ansible localhost -m copy –a Ask ‘src=/p...
Ansible Concepts: Playbooks 
60 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Ansible Concepts: Playbooks 
ansible-playbook [–i <inventory>] <playbook> 
Playbooks 
» Describe policies your remote syst...
Excursion to YAML 
YAML (YAML Ain’t No Markup Language): Motivation 
» “All data structures can be expressed via dicts, li...
YAML Excursion » Dictionaries 
--- # Block 
name: Michael Jordan 
age: 34 
--- # Inline 
{ name: Michael Jordan, age: 34 }...
YAML Excursion » Dictionaries 
--- # Block 
name: Michael Jordan 
age: 34 
--- # Inline 
{ name: Michael Jordan, age: 34 }...
YAML Excursion » Dictionaries 
--- # Block 
name: Michael Jordan 
age: 34 
--- # Inline 
{ name: Michael Jordan, age: 34 }...
YAML Excursion » Dictionaries 
--- # Block 
name: Michael Jordan 
age: 34 
Comment 
Optional quotes 
for Strings 
--- # In...
YAML Excursion » Lists 
--- # Block 
- milk 
- bread 
- butter 
--- # Inline 
[milk, bread, butter] 
67 COMPANY CONFIDENTI...
YAML Excursion » Lists 
--- # Block 
- milk 
- bread 
- butter 
--- # Inline 
[milk, bread, butter] 
Items start with 
hyp...
YAML Excursion » Lists 
--- # Block 
- milk 
- bread 
- butter 
--- # Inline 
[Smaimlke, bread, butter] 
indentation 
leve...
YAML Excursion » Complex 
--- 
men: 
- { name: Jimi Hendrix, year: 1970 } 
- { name: Jim Morrison, year: 1971 } 
women: 
-...
YAML Excursion » Complex 
List 
--- 
men: 
- { name: Jimi Hendrix, year: 1970 } 
- { name: Jim Morrison, year: 1971 } 
wom...
YAML Excursion » Complex 
Dictionary 
--- 
men: 
- { name: Jimi Hendrix, year: 1970 } 
- { name: Jim Morrison, year: 1971 ...
Ansible Concepts: Playbooks 
--- # appservers.yml 
- hosts: frontends:backends 
vars_files: 
- variables.yml 
handlers: 
-...
Ansible Concepts: Playbooks 
# production 
[frontends] 
frontend.example.com 
[backends] 
backend.example.com 
[frontends:...
Ansible Concepts: Playbooks 
# templates/tomcat-setenv.sh 
CATALINA_OPTS="$CATALINA_OPTS  
-agentpath:{{ dt_agent_dir }}/l...
Ansible Concepts: Playbooks 
--- # variables.yml 
tomcat_home: /opt/tomcat 
dt_agent_dir: /opt/dynatrace/agents 
dt_collec...
Ansible Concepts: Playbooks 
ansible-playbook –i production appservers.yml 
Run! 
PLAY [frontends:backends] 
*************...
Ansible Concepts: Playbooks 
--- # playbook.yml 
- include: appservers.yml 
- include: dbservers.yml 
- include: webserver...
Ansible Concepts: Playbooks » Variables 
Usage 
» {{ foo }} 
» {{ foo[i] }} 
» {{ foo.bar }} 
» Hello, my name is {{ foo }...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Advance Usage 
» {{ foo | mandatory }} 
» {{ foo | default(0) }} 
» {{ list| min ...
Ansible Concepts: Playbooks » Variables 
Validity 
» Valid: ‘foo_bar’, ‘foo5’ 
» Invalid: ‘foo-bar’, ‘foo bar’, ‘foo.bar’,...
Ansible Concepts: Playbooks » Variables 
--- # playbook.yml 
- hosts: all 
vars: 
- cleanup_home: yes 
- settings: 
ports:...
Ansible Concepts: Playbooks » Variables 
--- # playbook.yml 
- hosts: all 
vars_files: 
- variables.yml 
… 
--- # variable...
Ansible Concepts: Playbooks » Variables 
--- # playbook.yml 
- hosts: all 
tasks: 
- { include: create-user.yml, user: dep...
Ansible Concepts: Playbooks » Variables 
--- # playbook.yml 
- hosts: all 
roles: 
- { role: create-user, user: deploy } 
...
Ansible Concepts: Playbooks » Variables 
ansible –e ‘user=deploy’ playbook.yml 
Defined at 
invocation 
91 COMPANY CONFIDE...
Ansible Concepts: Playbooks » Tasks 
Tasks are... 
» invocations of Ansible modules 
» the units that do the actual deploy...
Ansible Concepts: Playbooks » Tasks 
Example: Install package ‘apache2’ 
--- # webservers.yml 
- hosts: webservers 
tasks:...
Ansible Concepts: Playbooks » Tasks 
Example: Copy file from src (localhost) to dest (remote host) 
--- # webservers.yml 
...
Ansible Concepts: Playbooks » Roles 
Roles 
» Are the preferred means to organize and reuse related tasks 
» Build on the ...
Ansible Concepts: Playbooks » Roles 
Reusing Roles in a Play 
--- # webservers.yml 
- hosts: webservers 
roles: 
- { role:...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
Ansible Concepts: Playbooks » Roles 
Best Practice: Directory Layout for Role-based Playbooks 
playbook.yml 
appservers.ym...
107 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
Upcoming SlideShare
Loading in …5
×

Automated Deployments

2,193 views

Published on

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.

Published in: Software
  • Be the first to comment

Automated Deployments

  1. 1. Automated Deployments – Hands-On Orlando, October 2014 Martin Etmajer martin.etmajer@dynatrace.com Senior Technology Strategist @ Dynatrace 1 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  2. 2. image here “ Martin Etmajer Insert headshot Senior Technology Strategist @ Dynatrace martin.etmajer@dynatrace.com @metmajer 2 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  3. 3. From Continuous Integration to Continuous Delivery 3 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  4. 4. Continuous Integration 4 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  5. 5. Continuous Integration 5 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  6. 6. Continuous Integration 6 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  7. 7. Continuous Integration 7 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  8. 8. Continuous Delivery Build Pipeline 8 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  9. 9. Continuous Delivery Build Pipeline 9 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  10. 10. Continuous Delivery Build Pipeline ✔ 10 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  11. 11. Continuous Delivery Build Pipeline ✔ 11 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  12. 12. Continuous Delivery Build Pipeline ✔ ✔ 12 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  13. 13. Continuous Delivery Build Pipeline ✔ ✔ 13 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  14. 14. Continuous Delivery Build Pipeline ✔ ✔ ✔ 14 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  15. 15. Continuous Delivery Build Pipeline ✔ ✔ ✔ 15 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  16. 16. Continuous Delivery Build Pipeline ✔ ✔ ✔ ✔ 16 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  17. 17. Continuous Delivery Build Pipeline ✔ ✔ ✔ ✔ 17 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  18. 18. Continuous Delivery Build Pipeline ✔ ✔ ✔ ✔ ✔ 18 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  19. 19. Introduction to Automated Deployments 19 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  20. 20. 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.” 20 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  21. 21. Benefits: Automation 21 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  22. 22. Benefits: Automation 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) Recreate Environments 22 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  23. 23. Benefits: Automation 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 23 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  24. 24. Implement and test Verification DEVELOPMENT OPERATIONS Benefits: Automation current iteration (2 weeks) time Planning 24 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  25. 25. 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 25 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  26. 26. 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,… 26 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  27. 27. Benefits: Auditability 27 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  28. 28. 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” 28 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  29. 29. Benefits: Repeatability 29 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  30. 30. 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 30 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  31. 31. 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 31 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  32. 32. Deployment Automation Solutions: Agent-based vs. Agentless 32 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  33. 33. Agent-Based Solutions 33 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  34. 34. Agent-Based Deployments (Chef, Puppet) 34 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  35. 35. Agent-Based Deployments (Chef, Puppet) 35 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  36. 36. Agent-Based Deployments (Chef, Puppet) 36 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  37. 37. 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 37 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  38. 38. 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 38 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  39. 39. Agentless Solutions 39 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  40. 40. Agentless Deployments (Ansible) 40 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  41. 41. Agentless Deployments (Ansible) 41 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  42. 42. Agentless Deployments (Ansible) 42 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  43. 43. Agentless Deployments (Ansible) 43 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  44. 44. Agentless Deployments 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 44 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  45. 45. Hands-On Training: Environment 45 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  46. 46. Sample Environment Web Server Frontend Application Server Backend Application Server Database check out deploy VCS Build Automation 46 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  47. 47. Sample Environment Apache Apache Tomcat Apache Tomcat PostgreSQL Web Server Frontend Application Server Backend Application Server Database Git VCS Jenkins check out deploy Build Automation 47 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  48. 48. Use Case: Deploy Dynatrace Agents Apache Apache Tomcat Apache Tomcat PostgreSQL Web Server Frontend Application Server Backend Application Server Database Git VCS Jenkins check out deploy Build Automation 48 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  49. 49. Use Case: Deploy Dynatrace Agents Apache Apache Tomcat Apache Tomcat PostgreSQL Web Server Frontend Application Server Backend Application Server Database Git VCS Jenkins check out deploy Build Automation Dynatrace Server 49 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  50. 50. Hands-On Training: Environment 50 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  51. 51. Today you will learn how to automatically... 1. Inject dynaTrace Agents into Apache Tomcats 2. Load database data into PostgreSQL 3. Integrate all this into Jenkins 51 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  52. 52. Ansible: Core Concepts 52 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  53. 53. Ansible Concepts: Inventories 53 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  54. 54. 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 54 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  55. 55. Ansible Concepts: Inventories [frontends] frontend.example.com [backends] backend.example.com [frontends:vars] dt_agent_name=frontend Group Variables Variable [backends:vars] dt_agent_name=backend Group Host 55 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  56. 56. Ansible Concepts: Ad-hoc Commands 56 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  57. 57. Ansible Concepts: Ad-hoc Commands ansible <host-pattern> [options] Module Arguments 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 57 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  58. 58. Ansible Concepts: Ad-hoc Commands ansible <host-pattern> [options] Examples? Forks » 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 58 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  59. 59. Ansible Concepts: Ad-hoc Commands ansible <host-pattern> [options] Examples? » ansible localhost -m copy –a Ask ‘src=/password usr/bin/a dest=/usr/bin/b’ » User Use sudo ansible appservers –a ‘/sbin/reboot’ interactively –f 10 » ansible appservers –a ‘/sbin/reboot’ –f 10 –u deploy ––sudo ––ask–sudo–pass 59 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  60. 60. Ansible Concepts: Playbooks 60 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  61. 61. 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 61 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  62. 62. Excursion to YAML 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 62 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  63. 63. YAML Excursion » Dictionaries --- # Block name: Michael Jordan age: 34 --- # Inline { name: Michael Jordan, age: 34 } 63 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  64. 64. YAML Excursion » Dictionaries --- # Block name: Michael Jordan age: 34 --- # Inline { name: Michael Jordan, age: 34 } Document 64 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  65. 65. YAML Excursion » Dictionaries --- # Block name: Michael Jordan age: 34 --- # Inline { name: Michael Jordan, age: 34 } key: value Same Indentation level 65 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  66. 66. YAML Excursion » Dictionaries --- # Block name: Michael Jordan age: 34 Comment Optional quotes for Strings --- # Inline { name: Michael Jordan, age: 34 } 66 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  67. 67. YAML Excursion » Lists --- # Block - milk - bread - butter --- # Inline [milk, bread, butter] 67 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  68. 68. YAML Excursion » Lists --- # Block - milk - bread - butter --- # Inline [milk, bread, butter] Items start with hyphen + space 68 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  69. 69. YAML Excursion » Lists --- # Block - milk - bread - butter --- # Inline [Smaimlke, bread, butter] indentation level 69 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  70. 70. YAML Excursion » Complex --- men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 } women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 } 70 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  71. 71. YAML Excursion » Complex List --- men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 } women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 } Dictionary 71 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  72. 72. YAML Excursion » Complex Dictionary --- men: - { name: Jimi Hendrix, year: 1970 } - { name: Jim Morrison, year: 1971 } women: - { name: Janis Joplin, year: 1970 } - { name: Amy Winehouse, year: 2011 } List 72 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  73. 73. Ansible Concepts: Playbooks --- # appservers.yml - hosts: frontends:backends vars_files: - variables.yml handlers: - name: restart tomcat Play 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 73 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  74. 74. Ansible Concepts: Playbooks # production [frontends] frontend.example.com [backends] backend.example.com [frontends:vars] dt_agent_name=frontend [backends:vars] dt_agent_name=backend 74 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  75. 75. 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 }}" 75 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  76. 76. Ansible Concepts: Playbooks --- # variables.yml tomcat_home: /opt/tomcat dt_agent_dir: /opt/dynatrace/agents dt_collector_url: dynatrace.example.com 76 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  77. 77. Ansible Concepts: Playbooks ansible-playbook –i production appservers.yml Run! 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 77 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  78. 78. Ansible Concepts: Playbooks --- # playbook.yml - include: appservers.yml - include: dbservers.yml - include: webservers.yml Includes multiple plays into a single playbook 78 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  79. 79. Ansible Concepts: Playbooks » Variables Usage » {{ foo }} » {{ foo[i] }} » {{ foo.bar }} » Hello, my name is {{ foo }} » bit.ly/ansible-variables 79 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  80. 80. Ansible Concepts: Playbooks » Variables Advance Usage » {{ foo | mandatory }} » {{ foo | default(0) }} » {{ list| min }} » {{ list| unique }} » {{ list1 | union(list2) }} » bit.ly/ansible-variables 80 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  81. 81. 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 81 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  82. 82. 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 82 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  83. 83. 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’ 83 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  84. 84. 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’ 84 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  85. 85. Ansible Concepts: Playbooks » Variables Advance Usage » {{ foo | mandatory }} » {{ foo | default(0) }} » {{ list| min }} » {{ list| unique }} » {{ list1 | union(list2) }} » bit.ly/ansible-variables Computes a join of lists ‘list1 and ‘list2’ 85 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  86. 86. Ansible Concepts: Playbooks » Variables Validity » Valid: ‘foo_bar’, ‘foo5’ » Invalid: ‘foo-bar’, ‘foo bar’, ‘foo.bar’, ‘5foo’, ‘5’ 86 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  87. 87. Ansible Concepts: Playbooks » Variables --- # playbook.yml - hosts: all vars: - cleanup_home: yes - settings: ports: http: 80 ssl: 443 … Inlined 87 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  88. 88. Ansible Concepts: Playbooks » Variables --- # playbook.yml - hosts: all vars_files: - variables.yml … --- # variables.yml cleanup_home: yes settings: ports: http: 80 ssl: 443 Imported 88 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  89. 89. Ansible Concepts: Playbooks » Variables --- # playbook.yml - hosts: all tasks: - { include: create-user.yml, user: deploy } … Defined in task inclusion 89 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  90. 90. Ansible Concepts: Playbooks » Variables --- # playbook.yml - hosts: all roles: - { role: create-user, user: deploy } … Defined in role inclusion 90 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  91. 91. Ansible Concepts: Playbooks » Variables ansible –e ‘user=deploy’ playbook.yml Defined at invocation 91 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  92. 92. Ansible Concepts: Playbooks » Tasks Tasks are... » invocations of Ansible modules » the units that do the actual deployment and configuration » bit.ly/ansible-module 92 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  93. 93. 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 93 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  94. 94. 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 94 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  95. 95. 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 95 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  96. 96. Ansible Concepts: Playbooks » Roles Reusing Roles in a Play --- # webservers.yml - hosts: webservers roles: - { role: common } - { role: apache2 } remote_user: deploy sudo: yes 96 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  97. 97. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.yml Top-level Playbook /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 97 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  98. 98. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.yml Plays /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 98 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  99. 99. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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’ 99 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  100. 100. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 100 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  101. 101. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 101 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  102. 102. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.yml /roles/x /roles/x/meta/main.yml /roles/x/defaults/main.yml /roles/x/files /roles/x/handlers/Files main.yml /roles/x/tasks/main.yml /roles/x/templates/main.yml /roles/x/vars/main.yml 102 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  103. 103. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 103 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  104. 104. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 104 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  105. 105. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 105 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  106. 106. Ansible Concepts: Playbooks » Roles Best Practice: Directory Layout for Role-based Playbooks playbook.yml appservers.yml dbservers.yml webservers.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 106 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014
  107. 107. 107 COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE #Perform2014

×