SlideShare a Scribd company logo
●
●
○
○
○
○
●
○
○
- file: path=/etc/foo.conf mode=0644
- file:
path=/etc/foo.conf
mode=0644
- file: "path=/etc/foo.conf mode=0644"
- file:
path: /etc/foo.conf
mode: 0644
- file:
path: "{{ my_path }}"
owner: "foo"
group: "bar"
mode: "0644"
- copy:
dest: "{{ my_path }}"
content: " Some very long line
which needs to be wrapped"
- copy:
dest: "{{ my_path }}"
content: "FirstnSecondn"
- file:
path: "{{ my_path }}"
owner: foo
group: bar
mode: 0644
- copy:
dest: "{{ my_path }}"
content: >2-
Some very long line
which needs to be wrapped
- copy:
dest: "{{ my_path }}"
content: |
First
Second
● - { } [ ] * & ? | > ! % ` # @ :
- file:
path: "{{ my_path }}"
mode: 0644
●
- debug:
msg: "Path: {{ my_path }}"
● yes false
- copy:
dest: "{{ my_path }}"
content: "yes"
● yamllint
ansible all -i localhost, --connection local -m debug -a 'msg={{xxx}}' -e '{xxx: @asd}'
- file:
path: "{{ my_path }}"
owner: foo
group: bar
mode: 0644
- hosts: all
vars:
data:
aaa: bbb
ccc:
- ddd:
- eee
# Half tabs (4 spaces)
- file:
path: "{{ my_path }}"
owner: foo
group: bar
mode: 0644
# Inconsistent indentation
- hosts: all
vars:
data:
aaa: bbb
ccc:
- ddd:
- eee
● .yml .yaml .jon .json
● .yaml meta
●
●
○
●
○
○
# roles/role1/defaults/main.yaml
var1: aaa
# roles/role2/defaults/main.yaml
var1: bbb
# group_vars/all
var1: ccc
# role1/defaults/main.yaml
role1_var1: aaa
# role2/defaults/main.yaml
role2_var1: bbb
# group_vars/all
role2_var1: ccc
# roles/role1/defaults/main.yaml
role1_var1: aaa
# roles/role1/tasks/main.yaml
- debug:
msg: >
var1={{ role1_var1 }},
var2={{ role1_var2 }}
# group_vars/all
role1_var2: bbb
# roles/role1/defaults/main.yaml
role1_var1: aaa
# Must be defined by the user
role1_var2: null
# roles/role1/tasks/main.yaml
- debug:
msg: >
var1={{ role1_var1 }},
var2={{ role1_var2 }}
# group_vars/all
role1_var2: bbb
# roles/role1/defaults/main.yaml
role1_var1: aaa
# roles/role1/vars/main.yaml
role1_var2: bbb
# roles/role1/tasks/main.yaml
- debug:
msg: >
var1={{ role1_var1 }},
var2={{ role1_var2 }}
# roles/role1/defaults/main.yaml
role1_var1: aaa
role1_var2: bbb
# roles/role1/tasks/main.yaml
- debug:
msg: >
var1={{ role1_var1 }},
var2={{ role1_var2 }}
● vars defaults
# roles/role1/meta/main.yaml
dependencies:
- role2
# roles/role1/vars/main.yaml
role1_var1: bbb
# roles/role2/defaults/main.yaml
role1_var1: aaa
●
○
○
- file:
path: /etc/foo.conf
mode: 0644
- name: Set foo.conf mode
file:
path: /etc/foo.conf
mode: 0644
- cron:
name: Run my command
job: /usr/bin/my_prog
minute: "*"
hour: "*"
state: present
- cron:
name: Run my command
job: /usr/bin/my_prog
- cron:
name: Run my command
minute: "{{ minute }}"
hour: "{{ hour }}"
job: /usr/bin/my_prog
- package:
name: mysql-server
- template:
src: my.cnf.j2
dest: /etc/my.cnf
- service:
name: mysql
enabled: yes
state: started
- package:
name: mysql-server
tags:
- mysql_pkg
- template:
src: my.cnf.j2
dest: /etc/my.cnf
tags:
- mysql_config
- service:
name: mysql
enabled: yes
state: started
tags:
- mysql_service
# roles/mysql/tasks/main.yaml
- package:
name: "{{ mysql_pkg }}"
notify: Restart MySQL service
tags: mysql_pkg
- template:
src: my.cnf.j2
dest: "{{ mysql_config_path }}"
notify: Restart MySQL service
tags: mysql_config
- service:
name: "{{ mysql_service }}"
enabled: yes
tags: mysql_service
- service:
name: "{{ mysql_service }}"
state: started
register: mysql_service_started
tags: mysql_service
# roles/mysql/handlers/main.yaml
- name: Restart MySQL service
service:
name: "{{ mysql_service }}"
state: restarted
when: >
mysql_service_started is not defined or
not mysql_service_started.changed
# roles/mysql/defaults/main.yaml
mysql_pkg: mysql-server
mysql_config_path: /etc/my.cnf
mysql_service: mysql
- lineinfile:
path: /etc/selinux/config
regexp: ^SELINUX=
line: SELINUX=enforcing
- template:
src: selinux_config.j2
dest: /etc/selinux/config
●
●
# Desired config file (myapp.cfg):
[section1]
option11=value11
option12=value12
# myapp_role/templates/myapp.cfg.j2:
{{ myapp_config | encode_ini }}
# myapp_role/defaults/main.yaml:
myapp_config:
section1:
option11: value11
option12: value12
# myapp_role/tasks/main.yaml:
- name: Create config file
template:
dest: /etc/myapp/ myapp.cfg
src: myapp.cfg.j2
# myapp_role/defaults/main.yaml:
myapp_section1_option11: value1
myapp_section1_option12: value2
myapp_section1__default:
option11: "{{ myapp_section1_option11 }}"
option12: "{{ myapp_section1_option12 }}"
myapp_section1__custom: []
myapp_section1: "{{
myapp_section1__default.update(myapp_section1__custom)}}{{
myapp_section1__default}}"
myapp_config__default:
section1: "{{ myapp_section1 }}"
myapp_config__custom: {}
myapp_config: "{{
myapp_config__default.update(myapp_config__custom) }}{{
myapp_config__default }}"
# Desired config file (/etc/selinux/config):
SELINUX=enforcing
SELINUXTYPE=targeted
# roles/sudo/templates/selinux_config.j2:
{{ ansible_managed | comment }}
{{ selinux_config | encode_ini(ucase_prop=true) }}
# roles/selinux/defaults/main.yaml:
selinux_config:
selinux: enforcing
selinuxtype: targeted
# roles/selinux/tasks/main.yaml:
- name: Create config file
template:
dest: /etc/selinux/config
src: selinux_config.j2
● README.md
●
○
○
○
○
○
■
○
○
●
●
●
●
●
●
●
●
●
git clone https://github.com/jtyr/vagrantfile_config.git /tmp/vagrantfile_config
mkdir -p /tmp/test/roles && cd /tmp/test
git clone https://github.com/jtyr/ansible-nginx.git roles/nginx
git clone https://github.com/jtyr/ansible-config_encoder_filters.git roles/config_encoder_filters
ln -s /tmp/vagrantfile_config/Vagrantfile ./
cat > vagrant.yaml <<END
---
defaults:
provision_individual: yes
vms:
testvm1:
ports:
HTTP:
host: 8080
guest: 80
END
cat > site.yaml <<END
---
- hosts: all
become: yes
roles:
- nginx
END
vagrant up
vagrant provision
ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory site.yaml
vagrant ssh
ssh -p 10000 -i .vagrant/machines/test/virtualbox/private_key -l vagrant localhost
vagrant destroy -f
Best practices for ansible roles development

More Related Content

What's hot

Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
All Things Open
 
Evaluation of Cropping system
Evaluation of Cropping systemEvaluation of Cropping system
Evaluation of Cropping system
P RP
 
Ley farming ppt
Ley farming pptLey farming ppt
Ley farming ppt
Aaliya Afroz
 
Node Labels in YARN
Node Labels in YARNNode Labels in YARN
Node Labels in YARN
DataWorks Summit
 
JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門
Takahiro Kamada
 
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
Chanwoong Kim
 
ASP.NETからASP.NET Coreに移行した話
ASP.NETからASP.NET Coreに移行した話ASP.NETからASP.NET Coreに移行した話
ASP.NETからASP.NET Coreに移行した話
Taiga Takahari
 
入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き
土岐 孝平
 
Azure로 MMO게임 서비스하기
Azure로 MMO게임 서비스하기Azure로 MMO게임 서비스하기
Azure로 MMO게임 서비스하기
YEONG-CHEON YOU
 
Crop response production functions
Crop response production functionsCrop response production functions
Crop response production functions
Mahendra Anjana
 
Zero budget natural farming in Vegetable Crops
Zero budget natural farming  in Vegetable CropsZero budget natural farming  in Vegetable Crops
Zero budget natural farming in Vegetable Crops
GBPUA&T, Pantnagar, (US Nagar)
 
Intercropping mixed cropping_principles_and_assessment_of_yield
Intercropping mixed cropping_principles_and_assessment_of_yieldIntercropping mixed cropping_principles_and_assessment_of_yield
Intercropping mixed cropping_principles_and_assessment_of_yield
9927850502
 
HttpClient詳解、或いは非同期の落とし穴について
HttpClient詳解、或いは非同期の落とし穴についてHttpClient詳解、或いは非同期の落とし穴について
HttpClient詳解、或いは非同期の落とし穴について
Yoshifumi Kawai
 
Organic farming.
Organic farming.Organic farming.
Organic farming.
Vaishnavi Choudam
 
Decision support system : Concept and application
Decision support system : Concept and applicationDecision support system : Concept and application
Decision support system : Concept and application
Kawita Bhatt
 
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Databricks
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
VMware Tanzu
 
The Five Stages of Enterprise Jupyter Deployment
The Five Stages of Enterprise Jupyter DeploymentThe Five Stages of Enterprise Jupyter Deployment
The Five Stages of Enterprise Jupyter Deployment
Frederick Reiss
 
Laravel로 스타트업 기술 스택 구성하기
Laravel로 스타트업 기술 스택 구성하기Laravel로 스타트업 기술 스택 구성하기
Laravel로 스타트업 기술 스택 구성하기
KwangSeob Jeong
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1
Hong-Gi Joe
 

What's hot (20)

Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
 
Evaluation of Cropping system
Evaluation of Cropping systemEvaluation of Cropping system
Evaluation of Cropping system
 
Ley farming ppt
Ley farming pptLey farming ppt
Ley farming ppt
 
Node Labels in YARN
Node Labels in YARNNode Labels in YARN
Node Labels in YARN
 
JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門
 
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
 
ASP.NETからASP.NET Coreに移行した話
ASP.NETからASP.NET Coreに移行した話ASP.NETからASP.NET Coreに移行した話
ASP.NETからASP.NET Coreに移行した話
 
入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き
 
Azure로 MMO게임 서비스하기
Azure로 MMO게임 서비스하기Azure로 MMO게임 서비스하기
Azure로 MMO게임 서비스하기
 
Crop response production functions
Crop response production functionsCrop response production functions
Crop response production functions
 
Zero budget natural farming in Vegetable Crops
Zero budget natural farming  in Vegetable CropsZero budget natural farming  in Vegetable Crops
Zero budget natural farming in Vegetable Crops
 
Intercropping mixed cropping_principles_and_assessment_of_yield
Intercropping mixed cropping_principles_and_assessment_of_yieldIntercropping mixed cropping_principles_and_assessment_of_yield
Intercropping mixed cropping_principles_and_assessment_of_yield
 
HttpClient詳解、或いは非同期の落とし穴について
HttpClient詳解、或いは非同期の落とし穴についてHttpClient詳解、或いは非同期の落とし穴について
HttpClient詳解、或いは非同期の落とし穴について
 
Organic farming.
Organic farming.Organic farming.
Organic farming.
 
Decision support system : Concept and application
Decision support system : Concept and applicationDecision support system : Concept and application
Decision support system : Concept and application
 
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
 
The Five Stages of Enterprise Jupyter Deployment
The Five Stages of Enterprise Jupyter DeploymentThe Five Stages of Enterprise Jupyter Deployment
The Five Stages of Enterprise Jupyter Deployment
 
Laravel로 스타트업 기술 스택 구성하기
Laravel로 스타트업 기술 스택 구성하기Laravel로 스타트업 기술 스택 구성하기
Laravel로 스타트업 기술 스택 구성하기
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1
 

Similar to Best practices for ansible roles development

Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
 
Composer
ComposerComposer
Composer
Tom Corrigan
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
grim_radical
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Омские ИТ-субботники
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappersPositive Hack Days
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration management
Alexander Tkachev
 
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
raccoony
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
Miva
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
Puppet
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
lutter
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
Mila Frerichs
 
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
Puppet
 
Puppetcamp module design talk
Puppetcamp module design talkPuppetcamp module design talk
Puppetcamp module design talk
Jeremy Kitchen
 
Centos config
Centos configCentos config
Centos config
Muhammad Abdi
 
Webinar - Managing Files with Puppet
Webinar - Managing Files with PuppetWebinar - Managing Files with Puppet
Webinar - Managing Files with PuppetOlinData
 
Hadoop installation on windows
Hadoop installation on windows Hadoop installation on windows
Hadoop installation on windows
habeebulla g
 
Linux command line cheatsheet
Linux command line cheatsheetLinux command line cheatsheet
Linux command line cheatsheet
We Ihaveapc
 
Big data using Hadoop, Hive, Sqoop with Installation
Big data using Hadoop, Hive, Sqoop with InstallationBig data using Hadoop, Hive, Sqoop with Installation
Big data using Hadoop, Hive, Sqoop with Installation
mellempudilavanya999
 

Similar to Best practices for ansible roles development (20)

Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Composer
ComposerComposer
Composer
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration management
 
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
 
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
 
Puppetcamp module design talk
Puppetcamp module design talkPuppetcamp module design talk
Puppetcamp module design talk
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
 
Centos config
Centos configCentos config
Centos config
 
Webinar - Managing Files with Puppet
Webinar - Managing Files with PuppetWebinar - Managing Files with Puppet
Webinar - Managing Files with Puppet
 
Hadoop installation on windows
Hadoop installation on windows Hadoop installation on windows
Hadoop installation on windows
 
Linux command line cheatsheet
Linux command line cheatsheetLinux command line cheatsheet
Linux command line cheatsheet
 
Big data using Hadoop, Hive, Sqoop with Installation
Big data using Hadoop, Hive, Sqoop with InstallationBig data using Hadoop, Hive, Sqoop with Installation
Big data using Hadoop, Hive, Sqoop with Installation
 

More from jtyr

Ansible Inventory Plugins
Ansible Inventory PluginsAnsible Inventory Plugins
Ansible Inventory Plugins
jtyr
 
Ansible Callback Plugins
Ansible Callback PluginsAnsible Callback Plugins
Ansible Callback Plugins
jtyr
 
Managing VMware VMs with Ansible
Managing VMware VMs with AnsibleManaging VMware VMs with Ansible
Managing VMware VMs with Ansible
jtyr
 
How does Ansible's agentless architecture work?
How does Ansible's agentless architecture work?How does Ansible's agentless architecture work?
How does Ansible's agentless architecture work?
jtyr
 
Variable precedence: Where should I put a variable?
Variable precedence: Where should I put a variable?Variable precedence: Where should I put a variable?
Variable precedence: Where should I put a variable?
jtyr
 
Managing multiple environments with Ansible
Managing multiple environments with AnsibleManaging multiple environments with Ansible
Managing multiple environments with Ansible
jtyr
 
Jinja2 filters
Jinja2 filtersJinja2 filters
Jinja2 filters
jtyr
 
Templating in ansible
Templating in ansibleTemplating in ansible
Templating in ansible
jtyr
 
Make the prompt great again
Make the prompt great againMake the prompt great again
Make the prompt great again
jtyr
 
Development of Ansible modules
Development of Ansible modulesDevelopment of Ansible modules
Development of Ansible modules
jtyr
 
Overcoming problems of the standard Ansible inventory file
Overcoming problems of the standard Ansible inventory fileOvercoming problems of the standard Ansible inventory file
Overcoming problems of the standard Ansible inventory file
jtyr
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
jtyr
 
LEGO IR Controller
LEGO IR ControllerLEGO IR Controller
LEGO IR Controller
jtyr
 

More from jtyr (13)

Ansible Inventory Plugins
Ansible Inventory PluginsAnsible Inventory Plugins
Ansible Inventory Plugins
 
Ansible Callback Plugins
Ansible Callback PluginsAnsible Callback Plugins
Ansible Callback Plugins
 
Managing VMware VMs with Ansible
Managing VMware VMs with AnsibleManaging VMware VMs with Ansible
Managing VMware VMs with Ansible
 
How does Ansible's agentless architecture work?
How does Ansible's agentless architecture work?How does Ansible's agentless architecture work?
How does Ansible's agentless architecture work?
 
Variable precedence: Where should I put a variable?
Variable precedence: Where should I put a variable?Variable precedence: Where should I put a variable?
Variable precedence: Where should I put a variable?
 
Managing multiple environments with Ansible
Managing multiple environments with AnsibleManaging multiple environments with Ansible
Managing multiple environments with Ansible
 
Jinja2 filters
Jinja2 filtersJinja2 filters
Jinja2 filters
 
Templating in ansible
Templating in ansibleTemplating in ansible
Templating in ansible
 
Make the prompt great again
Make the prompt great againMake the prompt great again
Make the prompt great again
 
Development of Ansible modules
Development of Ansible modulesDevelopment of Ansible modules
Development of Ansible modules
 
Overcoming problems of the standard Ansible inventory file
Overcoming problems of the standard Ansible inventory fileOvercoming problems of the standard Ansible inventory file
Overcoming problems of the standard Ansible inventory file
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
LEGO IR Controller
LEGO IR ControllerLEGO IR Controller
LEGO IR Controller
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Best practices for ansible roles development

  • 1.
  • 3.
  • 4. - file: path=/etc/foo.conf mode=0644 - file: path=/etc/foo.conf mode=0644 - file: "path=/etc/foo.conf mode=0644" - file: path: /etc/foo.conf mode: 0644
  • 5.
  • 6. - file: path: "{{ my_path }}" owner: "foo" group: "bar" mode: "0644" - copy: dest: "{{ my_path }}" content: " Some very long line which needs to be wrapped" - copy: dest: "{{ my_path }}" content: "FirstnSecondn" - file: path: "{{ my_path }}" owner: foo group: bar mode: 0644 - copy: dest: "{{ my_path }}" content: >2- Some very long line which needs to be wrapped - copy: dest: "{{ my_path }}" content: | First Second
  • 7. ● - { } [ ] * & ? | > ! % ` # @ : - file: path: "{{ my_path }}" mode: 0644 ● - debug: msg: "Path: {{ my_path }}" ● yes false - copy: dest: "{{ my_path }}" content: "yes" ● yamllint ansible all -i localhost, --connection local -m debug -a 'msg={{xxx}}' -e '{xxx: @asd}'
  • 8.
  • 9. - file: path: "{{ my_path }}" owner: foo group: bar mode: 0644 - hosts: all vars: data: aaa: bbb ccc: - ddd: - eee # Half tabs (4 spaces) - file: path: "{{ my_path }}" owner: foo group: bar mode: 0644 # Inconsistent indentation - hosts: all vars: data: aaa: bbb ccc: - ddd: - eee
  • 10.
  • 11. ● .yml .yaml .jon .json ● .yaml meta
  • 12.
  • 14.
  • 15. # roles/role1/defaults/main.yaml var1: aaa # roles/role2/defaults/main.yaml var1: bbb # group_vars/all var1: ccc # role1/defaults/main.yaml role1_var1: aaa # role2/defaults/main.yaml role2_var1: bbb # group_vars/all role2_var1: ccc
  • 16.
  • 17. # roles/role1/defaults/main.yaml role1_var1: aaa # roles/role1/tasks/main.yaml - debug: msg: > var1={{ role1_var1 }}, var2={{ role1_var2 }} # group_vars/all role1_var2: bbb # roles/role1/defaults/main.yaml role1_var1: aaa # Must be defined by the user role1_var2: null # roles/role1/tasks/main.yaml - debug: msg: > var1={{ role1_var1 }}, var2={{ role1_var2 }} # group_vars/all role1_var2: bbb
  • 18.
  • 19. # roles/role1/defaults/main.yaml role1_var1: aaa # roles/role1/vars/main.yaml role1_var2: bbb # roles/role1/tasks/main.yaml - debug: msg: > var1={{ role1_var1 }}, var2={{ role1_var2 }} # roles/role1/defaults/main.yaml role1_var1: aaa role1_var2: bbb # roles/role1/tasks/main.yaml - debug: msg: > var1={{ role1_var1 }}, var2={{ role1_var2 }}
  • 20. ● vars defaults # roles/role1/meta/main.yaml dependencies: - role2 # roles/role1/vars/main.yaml role1_var1: bbb # roles/role2/defaults/main.yaml role1_var1: aaa ● ○ ○
  • 21.
  • 22. - file: path: /etc/foo.conf mode: 0644 - name: Set foo.conf mode file: path: /etc/foo.conf mode: 0644
  • 23.
  • 24. - cron: name: Run my command job: /usr/bin/my_prog minute: "*" hour: "*" state: present - cron: name: Run my command job: /usr/bin/my_prog - cron: name: Run my command minute: "{{ minute }}" hour: "{{ hour }}" job: /usr/bin/my_prog
  • 25.
  • 26. - package: name: mysql-server - template: src: my.cnf.j2 dest: /etc/my.cnf - service: name: mysql enabled: yes state: started - package: name: mysql-server tags: - mysql_pkg - template: src: my.cnf.j2 dest: /etc/my.cnf tags: - mysql_config - service: name: mysql enabled: yes state: started tags: - mysql_service
  • 27. # roles/mysql/tasks/main.yaml - package: name: "{{ mysql_pkg }}" notify: Restart MySQL service tags: mysql_pkg - template: src: my.cnf.j2 dest: "{{ mysql_config_path }}" notify: Restart MySQL service tags: mysql_config - service: name: "{{ mysql_service }}" enabled: yes tags: mysql_service - service: name: "{{ mysql_service }}" state: started register: mysql_service_started tags: mysql_service # roles/mysql/handlers/main.yaml - name: Restart MySQL service service: name: "{{ mysql_service }}" state: restarted when: > mysql_service_started is not defined or not mysql_service_started.changed # roles/mysql/defaults/main.yaml mysql_pkg: mysql-server mysql_config_path: /etc/my.cnf mysql_service: mysql
  • 28.
  • 29. - lineinfile: path: /etc/selinux/config regexp: ^SELINUX= line: SELINUX=enforcing - template: src: selinux_config.j2 dest: /etc/selinux/config
  • 30.
  • 32. # Desired config file (myapp.cfg): [section1] option11=value11 option12=value12 # myapp_role/templates/myapp.cfg.j2: {{ myapp_config | encode_ini }} # myapp_role/defaults/main.yaml: myapp_config: section1: option11: value11 option12: value12 # myapp_role/tasks/main.yaml: - name: Create config file template: dest: /etc/myapp/ myapp.cfg src: myapp.cfg.j2
  • 33. # myapp_role/defaults/main.yaml: myapp_section1_option11: value1 myapp_section1_option12: value2 myapp_section1__default: option11: "{{ myapp_section1_option11 }}" option12: "{{ myapp_section1_option12 }}" myapp_section1__custom: [] myapp_section1: "{{ myapp_section1__default.update(myapp_section1__custom)}}{{ myapp_section1__default}}" myapp_config__default: section1: "{{ myapp_section1 }}" myapp_config__custom: {} myapp_config: "{{ myapp_config__default.update(myapp_config__custom) }}{{ myapp_config__default }}"
  • 34. # Desired config file (/etc/selinux/config): SELINUX=enforcing SELINUXTYPE=targeted # roles/sudo/templates/selinux_config.j2: {{ ansible_managed | comment }} {{ selinux_config | encode_ini(ucase_prop=true) }} # roles/selinux/defaults/main.yaml: selinux_config: selinux: enforcing selinuxtype: targeted # roles/selinux/tasks/main.yaml: - name: Create config file template: dest: /etc/selinux/config src: selinux_config.j2
  • 35.
  • 37.
  • 39. git clone https://github.com/jtyr/vagrantfile_config.git /tmp/vagrantfile_config mkdir -p /tmp/test/roles && cd /tmp/test git clone https://github.com/jtyr/ansible-nginx.git roles/nginx git clone https://github.com/jtyr/ansible-config_encoder_filters.git roles/config_encoder_filters ln -s /tmp/vagrantfile_config/Vagrantfile ./ cat > vagrant.yaml <<END --- defaults: provision_individual: yes vms: testvm1: ports: HTTP: host: 8080 guest: 80 END cat > site.yaml <<END --- - hosts: all become: yes roles: - nginx END vagrant up vagrant provision ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory site.yaml vagrant ssh ssh -p 10000 -i .vagrant/machines/test/virtualbox/private_key -l vagrant localhost vagrant destroy -f