SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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)
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie AnsibleFest 2014 - Role Tips and Tricks

playbooks.pptx
playbooks.pptxplaybooks.pptx
playbooks.pptx
BaskarKannanK
 

Ähnlich wie 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
 

Kürzlich hochgeladen

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
dharasingh5698
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Kürzlich hochgeladen (20)

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
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
 
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
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
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
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 

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