SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
WRITING ROLES: TIPS & TRICKS 
James Cammarata 
(github: jimi-c)
ABOUT ME 
STL Native, previously worked for Savvis/CenturyLink and 
Scottrade 
Started contributing to Cobbler in September of 2008, and took 
over the project leadership in 2010 
Joined Ansible in July, 2013
WHAT ARE ROLES?
GETTING STARTED
CREATING THE INITIAL ROLE LAYOUT
BAD! 
$ mkdir -p roles/myrole/{tasks,vars} 
$ touch roles/myrole/{tasks,vars}/main.yml 
This is a very manual process, and completely unnecessary...
A MUCH BETTER WAY ™ 
$ ansible-galaxy init roles/myrole 
Benefits include: 
Creates ALL of the directory structure for you 
Stubs out some of the YAML files like `meta/main.yml`
USING ROLE DEPENDENCIES
SPECIFYING DEPENDENCIES IN METADATA 
Dependencies are specified in the `meta/main.yml` role file: 
dependencies: 
- foo 
- { role: foo } 
- { role: /path/to/some/dir/bar } 
- { role: bam, some_var: "hello world!" }
TAGS & CONDITIONALS WITH ROLE DEPENDENCIES
When applying a tag or conditional statemtent to a role 
definition, they are appended to those specified on any tasks 
within the role. For example: 
# main yaml file 
roles: 
- { role: foo, tags: 'foo', when: some_var == 'foo' } 
# roles/foo/meta/main.yml 
dependencies: 
- { role: bar } 
All tasks defined within 'bar' will also have the above tags and 
'when' statement applied to them, in addition to any other tags or 
conditionals defined on the task.
CROSS-PLATFORM ROLES 
TIPS & TRICKS
USE GATHERED FACTS + INCLUDE TO TARGET 
PLATFORMS
# apache/tasks/main.yml 
- include: redhat.yml 
when: ansible_os_family == 'RedHat' 
- include: debian.yml 
when: ansible_os_family == 'Debian' 
# apache/tasks/redhat.yml 
- name: install apache packages 
yum: name=httpd state=present 
# apache/tasks/debian.yml 
- name: install apache packages 
apt: name=apache2 state=present
HANDLERS AND SERVICE NAME DIFFERENCES 
Lets use the same method of conditional includes for handlers!
Results...
WHY DOESN'T THIS WORK? 
1. Handler names in Ansible must be unique. 
2. Included files are always read and parsed at load time, BUT the 
conditionals are not evaluated until the task is executed... 
3. Result - the last handler defined with the name "wins", and the 
wrong handler may be run.
THE SOLUTION: SET_FACT 
# apache/tasks/redhat.yml 
- name: install apache packages 
yum: name=httpd state=present 
- name: set the name of the service 
set_fact: apache_service_name=httpd 
# apache/tasks/debian.yml 
- name: install apache packages 
apt: name=apache2 state=present 
- name: set the name of the service 
set_fact: apache_service_name=apache2 
# apache/handlers/main.yml 
- name: restart apache service 
service: name={{apache_service_name}} state=restarted
DEALING WITH OTHER DIFFERENCES
We can use set_fact again in the platform-specific includes: 
# apache/tasks/redhat.yml 
- name: set variables for this OS 
set_fact: 
apache_service_name: httpd 
apache_user: apache 
apache_httpd_conf_path: /etc/httpd/conf/httpd.conf 
apache_httpd_confd_path: /etc/httpd/conf.d 
... 
# apache/tasks/debian.yml 
- name: set the name of the service 
set_fact: 
apache_service_name: apache2 
apache_user: www-data 
apache_httpd_conf_path: /etc/apache2/apache2.conf 
apache_httpd_confd_path: /etc/apache2/conf-available 
...
And in our updated common tasks/main.yml: 
# apache/tasks/main.yml 
# (continued) 
- name: deploy apache configuration 
template: 
src: httpd.conf.j2 
dest: "{{apache_httpd_conf_path}}" 
owner: "{{apache_user}}" 
mode: "0640" 
notify: restart apache service 
- name: make sure service is running and enabled 
service: 
name: "{{apache_service_name}}" 
state: running 
enabled: yes
ALTERNATIVE METHOD FOR VARIABLES
It is possible to use the include_vars and with_first_found lookup 
to include the distro-specific variables file, and to fall back to a 
default set of variables: 
# apache/tasks/main.yml 
- include_vars: "{{ item }}" 
with_first_found: 
- "{{ ansible_os_family }}.yml" 
- "default.yml"
GALAXY BEST PRACTICES
CREATING ACCURATE METADATA
When you use the ansible-galaxy CLI command to init a new role, 
a sample meta/main.yml is automatically created for you: 
--- 
galaxy_info: 
author: your name 
description: 
company: your company (optional) 
license: BSD 
min_ansible_version: 1.2 
#platforms: 
#- name: EL 
# versions: 
# - all 
# - 5 
# - 6 
# - 7 
... 
#categories: 
#- cloud 
... 
#- web 
dependencies: []
LISTING SANE DEPENDENCIES 
Dependencies listed in the metadata should only point to other 
Galaxy roles.
STEPS TO ADD YOUR ROLE TO GITHUB
AFTER CREATING YOUR REPO ON GITHUB: 
$ ansible-galaxy init foo 
$ cd foo/ 
$ git init 
- 
(edit your files here) 
- 
$ git add * 
$ git commit -m "initial commit for my role" 
$ git remote add origin https://github.com/yourname/your-ansible- 
role 
$ git push origin master
QUESTIONS?
THANKS!

Más contenido relacionado

La actualidad más candente

Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestrationbcoca
 
Breaking Up With Your Data Center Presentation
Breaking Up With Your Data Center PresentationBreaking Up With Your Data Center Presentation
Breaking Up With Your Data Center PresentationTelescope_Inc
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?shirou wakayama
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of AnsibleDevOps Ltd.
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
 
DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)Soshi Nemoto
 
Ansible 2 and Ansible Galaxy 2
Ansible 2 and Ansible Galaxy 2Ansible 2 and Ansible Galaxy 2
Ansible 2 and Ansible Galaxy 2Jeff Geerling
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupGreg DeKoenigsberg
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 

La actualidad más candente (20)

Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Breaking Up With Your Data Center Presentation
Breaking Up With Your Data Center PresentationBreaking Up With Your Data Center Presentation
Breaking Up With Your Data Center Presentation
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)
 
Ansible 2 and Ansible Galaxy 2
Ansible 2 and Ansible Galaxy 2Ansible 2 and Ansible Galaxy 2
Ansible 2 and Ansible Galaxy 2
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 

Destacado

What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015jimi-c
 
Achieving Continuous Delivery: An Automation Story
Achieving Continuous Delivery: An Automation StoryAchieving Continuous Delivery: An Automation Story
Achieving Continuous Delivery: An Automation Storyjimi-c
 
How to Automate Big Data with Ansible
How to Automate Big Data with AnsibleHow to Automate Big Data with Ansible
How to Automate Big Data with AnsibleBigstep
 
Ansible & CloudStack - Configuration Management
Ansible & CloudStack - Configuration ManagementAnsible & CloudStack - Configuration Management
Ansible & CloudStack - Configuration ManagementShapeBlue
 
Python (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationRick Sherman
 
Objective C Tricks
Objective C TricksObjective C Tricks
Objective C TricksInova LLC
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchMatteo Battaglio
 
The Great American Novel? TL;DR Writing for Web and Social in the Age of Brevity
The Great American Novel? TL;DR Writing for Web and Social in the Age of BrevityThe Great American Novel? TL;DR Writing for Web and Social in the Age of Brevity
The Great American Novel? TL;DR Writing for Web and Social in the Age of BrevityJeffrey Stevens
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerVineet Kumar Saini
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
 

Destacado (13)

What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015
 
Achieving Continuous Delivery: An Automation Story
Achieving Continuous Delivery: An Automation StoryAchieving Continuous Delivery: An Automation Story
Achieving Continuous Delivery: An Automation Story
 
Ansible ALLTHETHINGS
Ansible ALLTHETHINGSAnsible ALLTHETHINGS
Ansible ALLTHETHINGS
 
How to Automate Big Data with Ansible
How to Automate Big Data with AnsibleHow to Automate Big Data with Ansible
How to Automate Big Data with Ansible
 
Ansible & CloudStack - Configuration Management
Ansible & CloudStack - Configuration ManagementAnsible & CloudStack - Configuration Management
Ansible & CloudStack - Configuration Management
 
Python (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network Automation
 
Objective C Tricks
Objective C TricksObjective C Tricks
Objective C Tricks
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
EIRC- Literacy Consortium 2016
EIRC- Literacy Consortium 2016EIRC- Literacy Consortium 2016
EIRC- Literacy Consortium 2016
 
The Great American Novel? TL;DR Writing for Web and Social in the Age of Brevity
The Great American Novel? TL;DR Writing for Web and Social in the Age of BrevityThe Great American Novel? TL;DR Writing for Web and Social in the Age of Brevity
The Great American Novel? TL;DR Writing for Web and Social in the Age of Brevity
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 

Similar a AnsibleFest 2014 - Role Tips and Tricks

Ansible with oci
Ansible with ociAnsible with oci
Ansible with ociDonghuKIM2
 
Jenkins Job Builder: our experience
Jenkins Job Builder: our experienceJenkins Job Builder: our experience
Jenkins Job Builder: our experienceTimofey Turenko
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Ryan Brown
 
Ansible Devops North East - slides
Ansible Devops North East - slides Ansible Devops North East - slides
Ansible Devops North East - slides InfinityPP
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CICosmin Poieana
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!Jeff Geerling
 
Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)Jude A. Goonawardena
 
Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)iman darabi
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansibleahamilton55
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloudTahsin Hasan
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
Ember and containers
Ember and containersEmber and containers
Ember and containersMatthew Beale
 
Puppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfPuppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfDavid Danzilio
 
xml-motor ~ What,Why,How
xml-motor ~ What,Why,Howxml-motor ~ What,Why,How
xml-motor ~ What,Why,HowAbhishek Kumar
 
Fun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesFun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesabadger1999
 

Similar a AnsibleFest 2014 - Role Tips and Tricks (20)

Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
 
playbooks.pptx
playbooks.pptxplaybooks.pptx
playbooks.pptx
 
Jenkins Job Builder: our experience
Jenkins Job Builder: our experienceJenkins Job Builder: our experience
Jenkins Job Builder: our experience
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015
 
Ansible Devops North East - slides
Ansible Devops North East - slides Ansible Devops North East - slides
Ansible Devops North East - slides
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CI
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!
 
Generators
GeneratorsGenerators
Generators
 
Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)
 
Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Ansible 202 - sysarmy
Ansible 202 - sysarmyAnsible 202 - sysarmy
Ansible 202 - sysarmy
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Apache Hacks
Apache HacksApache Hacks
Apache Hacks
 
Ember and containers
Ember and containersEmber and containers
Ember and containers
 
Puppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfPuppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConf
 
xml-motor ~ What,Why,How
xml-motor ~ What,Why,Howxml-motor ~ What,Why,How
xml-motor ~ What,Why,How
 
Fun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesFun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker images
 

Último

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 

Último (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 

AnsibleFest 2014 - Role Tips and Tricks

  • 1. WRITING ROLES: TIPS & TRICKS James Cammarata (github: jimi-c)
  • 2. ABOUT ME STL Native, previously worked for Savvis/CenturyLink and Scottrade Started contributing to Cobbler in September of 2008, and took over the project leadership in 2010 Joined Ansible in July, 2013
  • 5. CREATING THE INITIAL ROLE LAYOUT
  • 6. BAD! $ mkdir -p roles/myrole/{tasks,vars} $ touch roles/myrole/{tasks,vars}/main.yml This is a very manual process, and completely unnecessary...
  • 7. A MUCH BETTER WAY ™ $ ansible-galaxy init roles/myrole Benefits include: Creates ALL of the directory structure for you Stubs out some of the YAML files like `meta/main.yml`
  • 9. SPECIFYING DEPENDENCIES IN METADATA Dependencies are specified in the `meta/main.yml` role file: dependencies: - foo - { role: foo } - { role: /path/to/some/dir/bar } - { role: bam, some_var: "hello world!" }
  • 10. TAGS & CONDITIONALS WITH ROLE DEPENDENCIES
  • 11. When applying a tag or conditional statemtent to a role definition, they are appended to those specified on any tasks within the role. For example: # main yaml file roles: - { role: foo, tags: 'foo', when: some_var == 'foo' } # roles/foo/meta/main.yml dependencies: - { role: bar } All tasks defined within 'bar' will also have the above tags and 'when' statement applied to them, in addition to any other tags or conditionals defined on the task.
  • 13. USE GATHERED FACTS + INCLUDE TO TARGET PLATFORMS
  • 14. # apache/tasks/main.yml - include: redhat.yml when: ansible_os_family == 'RedHat' - include: debian.yml when: ansible_os_family == 'Debian' # apache/tasks/redhat.yml - name: install apache packages yum: name=httpd state=present # apache/tasks/debian.yml - name: install apache packages apt: name=apache2 state=present
  • 15. HANDLERS AND SERVICE NAME DIFFERENCES Lets use the same method of conditional includes for handlers!
  • 17. WHY DOESN'T THIS WORK? 1. Handler names in Ansible must be unique. 2. Included files are always read and parsed at load time, BUT the conditionals are not evaluated until the task is executed... 3. Result - the last handler defined with the name "wins", and the wrong handler may be run.
  • 18. THE SOLUTION: SET_FACT # apache/tasks/redhat.yml - name: install apache packages yum: name=httpd state=present - name: set the name of the service set_fact: apache_service_name=httpd # apache/tasks/debian.yml - name: install apache packages apt: name=apache2 state=present - name: set the name of the service set_fact: apache_service_name=apache2 # apache/handlers/main.yml - name: restart apache service service: name={{apache_service_name}} state=restarted
  • 19. DEALING WITH OTHER DIFFERENCES
  • 20. We can use set_fact again in the platform-specific includes: # apache/tasks/redhat.yml - name: set variables for this OS set_fact: apache_service_name: httpd apache_user: apache apache_httpd_conf_path: /etc/httpd/conf/httpd.conf apache_httpd_confd_path: /etc/httpd/conf.d ... # apache/tasks/debian.yml - name: set the name of the service set_fact: apache_service_name: apache2 apache_user: www-data apache_httpd_conf_path: /etc/apache2/apache2.conf apache_httpd_confd_path: /etc/apache2/conf-available ...
  • 21. And in our updated common tasks/main.yml: # apache/tasks/main.yml # (continued) - name: deploy apache configuration template: src: httpd.conf.j2 dest: "{{apache_httpd_conf_path}}" owner: "{{apache_user}}" mode: "0640" notify: restart apache service - name: make sure service is running and enabled service: name: "{{apache_service_name}}" state: running enabled: yes
  • 23. It is possible to use the include_vars and with_first_found lookup to include the distro-specific variables file, and to fall back to a default set of variables: # apache/tasks/main.yml - include_vars: "{{ item }}" with_first_found: - "{{ ansible_os_family }}.yml" - "default.yml"
  • 26. When you use the ansible-galaxy CLI command to init a new role, a sample meta/main.yml is automatically created for you: --- galaxy_info: author: your name description: company: your company (optional) license: BSD min_ansible_version: 1.2 #platforms: #- name: EL # versions: # - all # - 5 # - 6 # - 7 ... #categories: #- cloud ... #- web dependencies: []
  • 27. LISTING SANE DEPENDENCIES Dependencies listed in the metadata should only point to other Galaxy roles.
  • 28. STEPS TO ADD YOUR ROLE TO GITHUB
  • 29. AFTER CREATING YOUR REPO ON GITHUB: $ ansible-galaxy init foo $ cd foo/ $ git init - (edit your files here) - $ git add * $ git commit -m "initial commit for my role" $ git remote add origin https://github.com/yourname/your-ansible- role $ git push origin master