SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
●
●
○
○
○
○
●
○
○
- 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

Contenu connexe

Tendances

Wily introscope 7.1 installation guide
Wily introscope 7.1   installation guideWily introscope 7.1   installation guide
Wily introscope 7.1 installation guideImam Nurhadi
 
Replacing Your Shared Drive with Alfresco - Open Source ECM
Replacing Your Shared Drive with Alfresco - Open Source ECMReplacing Your Shared Drive with Alfresco - Open Source ECM
Replacing Your Shared Drive with Alfresco - Open Source ECMAlfresco Software
 
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Anne Nicolas
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of playChris Simmonds
 
Linux on ARM 64-bit Architecture
Linux on ARM 64-bit ArchitectureLinux on ARM 64-bit Architecture
Linux on ARM 64-bit ArchitectureRyo Jin
 
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Maksim Shudrak
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoSherif Mousa
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
Embedded Linux/ Debian with ARM64 Platform
Embedded Linux/ Debian with ARM64 PlatformEmbedded Linux/ Debian with ARM64 Platform
Embedded Linux/ Debian with ARM64 PlatformSZ Lin
 
(美)大卫·舒尔茨《大思想的神奇》
(美)大卫·舒尔茨《大思想的神奇》(美)大卫·舒尔茨《大思想的神奇》
(美)大卫·舒尔茨《大思想的神奇》Joan Shi
 
Sap script made easy
Sap script made easySap script made easy
Sap script made easyKranthi Kumar
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
Channel in Go
Channel in GoChannel in Go
Channel in GoJaych Su
 
MediaPlayer Playing Flow
MediaPlayer Playing FlowMediaPlayer Playing Flow
MediaPlayer Playing FlowJavid Hsu
 

Tendances (20)

Wily introscope 7.1 installation guide
Wily introscope 7.1   installation guideWily introscope 7.1   installation guide
Wily introscope 7.1 installation guide
 
Replacing Your Shared Drive with Alfresco - Open Source ECM
Replacing Your Shared Drive with Alfresco - Open Source ECMReplacing Your Shared Drive with Alfresco - Open Source ECM
Replacing Your Shared Drive with Alfresco - Open Source ECM
 
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of play
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Linux on ARM 64-bit Architecture
Linux on ARM 64-bit ArchitectureLinux on ARM 64-bit Architecture
Linux on ARM 64-bit Architecture
 
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
 
Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Embedded Linux/ Debian with ARM64 Platform
Embedded Linux/ Debian with ARM64 PlatformEmbedded Linux/ Debian with ARM64 Platform
Embedded Linux/ Debian with ARM64 Platform
 
(美)大卫·舒尔茨《大思想的神奇》
(美)大卫·舒尔茨《大思想的神奇》(美)大卫·舒尔茨《大思想的神奇》
(美)大卫·舒尔茨《大思想的神奇》
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Sap script made easy
Sap script made easySap script made easy
Sap script made easy
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Channel in Go
Channel in GoChannel in Go
Channel in Go
 
Memory management
Memory managementMemory management
Memory management
 
UEFI presentation
UEFI presentationUEFI presentation
UEFI presentation
 
MediaPlayer Playing Flow
MediaPlayer Playing FlowMediaPlayer Playing Flow
MediaPlayer Playing Flow
 

Similaire à 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
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_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 managementAlexander 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 BoltonMiva
 
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 configurationlutter
 
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 lambdaMila 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 talkJeremy Kitchen
 
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 cheatsheetWe 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 Installationmellempudilavanya999
 

Similaire à 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
 

Plus de jtyr

Ansible Inventory Plugins
Ansible Inventory PluginsAnsible Inventory Plugins
Ansible Inventory Pluginsjtyr
 
Ansible Callback Plugins
Ansible Callback PluginsAnsible Callback Plugins
Ansible Callback Pluginsjtyr
 
Managing VMware VMs with Ansible
Managing VMware VMs with AnsibleManaging VMware VMs with Ansible
Managing VMware VMs with Ansiblejtyr
 
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 Ansiblejtyr
 
Jinja2 filters
Jinja2 filtersJinja2 filters
Jinja2 filtersjtyr
 
Templating in ansible
Templating in ansibleTemplating in ansible
Templating in ansiblejtyr
 
Make the prompt great again
Make the prompt great againMake the prompt great again
Make the prompt great againjtyr
 
Development of Ansible modules
Development of Ansible modulesDevelopment of Ansible modules
Development of Ansible modulesjtyr
 
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 filejtyr
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansiblejtyr
 
LEGO IR Controller
LEGO IR ControllerLEGO IR Controller
LEGO IR Controllerjtyr
 

Plus de 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
 

Dernier

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

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