SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
#OktoCampus
Workshop
Ansible
$> whoami
● Cédric DELGEHIER
● Ops @scalair
● Poor slide designer (sorry)
● Python lover
● Father of two wise children
Ansible : Introduction
● How to manage the installation, the update and
the configuration of all my servers ?
Ansible : Introduction
Variants : I use scripts, « for loop » or synchronized terminal
Ansible : Introduction
Where is the problem ?
Scripts are :
● Hard to maintain
● Boring in heterogeneous environments
● Not idempotent natively
I hope: centralized, versioned, documented, easy to read for a new colleague
An idempotent operation is one that has no additional effect if it is called more than once with the same input parameters
*
Ansible : Introduction
Ansible : Introduction
What's a provisioning framework?
● Automated setup of servers
● Configuration as code
Create users
Install software
Generate and manipulate
config files
Start/stop/restart
processes
Set up dependencies
between operations
Ansible : Introduction
Ansible
● Ansible is based on Python
● Standard SSH to connect to managed servers/nodes
● Push-based system
● Agentless operation
● No central server, no special software on managed nodes
● Facts from each node used for state-full decisions
● Idempotent ConfigMgmt tool (like others)
● Extend with custom modules, use any language which can return JSON
● Inventory from various datasource, return as JSON
An idempotent operation is one that has no additional effect if it is called more than once with the same input parameters
Ansible
● Ansible is similar to Chef, Puppet or Salt
● Shared purpose – solve tasks for CfgMgmt, provisioning, deployment, etc.
● Ansible may be simplest and easiest configuration management tool to start
● Chef, Puppet, Salt are great tools as well, may be more complex to start with, steeper
learning curve, etc.
● The absence of an agent allows it to manage more than servers (network or storage
equipment)
● It supports managing major cloud devices (AWS, RackSpace, Digital Ocean,
OpenStack) through a collection of modules which are available
Ansible
LAB
Setup
● Install VirtualBox & Vagrant
● Clone the repository on github
– git clone https://github.com/cdelgehier/oktocampus_ansible.git
● Run the Vagrantfile
– vagrant up (or vagrant up bastion prod1 prod2 for poor laptop)
● Connect you to your own bastion
– vagrant ssh bastion
● Generate your ssh key
– ssh-keygen -t rsa -b 2048
● Accept host ssh key file
– ssh-keyscan prod1 prod2 rec1 rec2 > ~/.ssh/known_hosts
README.md
Ansible : Ad Hoc mode
● You don't have to create an elaborate set of tasks just to perform simple operations
on your nodes
● An ad-hoc command consists of two parameters; the host group that defines on what
machines to run the task against and the Ansible module to run
ansible <group> -m <module>
$> ansible prod -m ping
$> ansible prod -m command -a 'whoami'
$> ansible prod -m setup
$> ansible prod -a 'hostnamectl'
-m command is by default
$> ansible all -a '/sbin/reboot' --forks=10
$> ansible recette -m user -a 'name=georges password=okto'
$> ansible alll -m yum -a 'name=nginx state=installed'
$> ansible alll -m service -a 'name=nginx state=started'
$> ansible all –list-hosts
$> ansible localhost -m debug -a 'var=groups.keys()'
Ansible
LAB
Part 1
In Ad Hoc only and with the manual
http://docs.ansible.com/ansible/list_of_all_modules.html
or with the ansible-doc commande
Try :
● To install a package (with yum) named epel-release then another named cowsay
● To run the command coway with moooo in argument
● Try add a user john which one is a member of the okto group
● Create a gzip archive of /etc/shadow into /tmp
Ansible
LAB
Part 1
● ansible all --become --module-name yum --args "name=epel-release state=present"
● ansible all -b -m yum -a "name=cowsay state=present"
● ansible all -a "cowsay moooo"
● ansible all -b -m group -a "name=okto"
● ansible all -b -m user -a "name=john group=okto"
● ansible all -b -m archive -a "path=/etc/shadow dest=/tmp/shadow.gz"
Ansible
Ansible : concepts
Ansible : concepts
● Modules : accomplish dedicated Tasks (set values, use templates)
● Tasks : execute Module specific parameters, variables, etc.
● Variables : configuration-wide, Playbook/Roles specific vars
● Facts : gather information about the target system
● Handlers : like Tasks but usually get called by another Task
● Roles : group related Tasks, encapsulate data to accomplish Task
● Files : files directory contains files copied over to target
● Templates : Jinja2 format with placeholders to insert variables
● Vault : encrypt sensible data
● Plays : are lists of Tasks wich apply to hosts / host groups
● Playbooks : YAML formatted files orchestrate steps sequentially
● Inventory : a combination of a hosts and groups
Ansible : concepts
.
|-- ansible.cfg #ansible config file
|-- inventory.ini #hosts file
`-- roles #roles directory
`-- role1 #a role directory
|-- defaults
| `-- main.yml #defaults values
|-- files #files directory
| `-- myfile.cfg
|-- handlers #handlers directory
| `-- main.yml
|-- tasks
| `-- main.yml #task file
|-- templates
| `-- mytemplate.conf.j2 #template file
`-- vars
`-- main.yml #variable file
A minimal top level directory would contain files and directories such as:
Ansible : Inventory
[prod]
prod1
10.0.15.21
[recette]
rec[1:2]
[jira]
{{ jira_ip }}
Inventory files are simple text files which describe
your servers
IP Addresses or DNS Names, grouped by names
Inventory files can take advantage of variables
and enumerations
Ansible : Playbooks
● YAML Files
● Declaratively define your configuration
● Can contain many « plays » targetting different
groups
Describe state (declarative)Describe what to do (imperative)
Ansible : Playbooks
---
- name : play 1
hosts: all
gather_facts: yes
become: yes
vars:
docroot: /var/www/html/
title: oktocampus
body: |
<h1>Hello all !</h1>
<p>Is there any pizza left ? :)</p>
tasks:
- name: install epel repo
tags: install
yum:
name: epel-release
state: present
- name: install apache httpd
tags: install
yum:
name: httpd
state: present
- name: start and enable httpd
tags: config
service:
name: httpd
state: started
enabled: yes
- name: install packages in loop
tags: install
yum:
name: "{{ item }}"
state: present
with_items:
- ca-certificates
- w3m
- name: templating of my awesome html file
tags: config
template:
src: index.html.j2
dest: "{{ docroot }}/index.html"
owner: apache
group: apache
roles:
- role: ntp
ntp_timezone: "Europe/Paris"
ntp_manage_config: true
ntp_area: "fr"
ntp_servers:
- "0.{{ ntp_area }}.pool.ntp.org iburst"
- "1.{{ ntp_area }}.pool.ntp.org iburst"
- "2.{{ ntp_area }}.pool.ntp.org iburst"
- "3.{{ ntp_area }}.pool.ntp.org iburst"
...
All YAML files can optionally begin with --- and end with ...
Define targets for this play
Ansible provides many facts about the system, automatically
This play needs a privilege escalation
Roles are played before tasks
Overwrite role's defaults
Module used
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
{{ body }}
# generated on {{ ansible_hostname }} OS: {{ ansible_distribution }}
{{ ansible_distribution_major_version }} ip: {{ ansible_eth1.ipv4.address }}
</body>
</html>
Ansible : Roles
$> ansible-galaxy init ntp
$> tree ntp
ntp
|-- defaults
| `-- main.yml
|-- files
|-- handlers
| `-- main.yml
|-- meta
| `-- main.yml
|-- README.md
|-- tasks
| `-- main.yml
|-- templates
| |-- ntp.conf.j2
| `-- timezone.j2
|-- tests
| |-- inventory
| `-- test.yml
`-- vars
|-- Debian.yml
|-- FreeBSD.yml
|-- main.yml
`-- RedHat.yml
Creation of a role folder
Variables customizable by the user
Variables specific to the role
Set of tests
---
- name: include distribution or OS Family variable
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- name: Ensure NTP-related packages are installed.
tags: install
package:
name: "{{ item }}"
state: present
with_items:
- ntp
- tzdata
- name: Set timezone
tags: config
timezone:
name: "{{ ntp_timezone }}"
- name: Ensure NTP is running and enabled as configured.
tags: config
service:
name: "{{ ntp_daemon }}"
state: started
enabled: yes
when: ntp_enabled
- name: Ensure NTP is stopped and disabled as configured.
tags: config
service:
name: "{{ ntp_daemon }}"
state: stopped
enabled: no
when: not ntp_enabled
- name: Generate ntp.conf file
tags: config
template:
src: ntp.conf.j2
dest: /etc/ntp.conf
notify: restart ntp
when: ntp_manage_config
...
---
ntp_enabled: true
ntp_timezone: "Etc/UTC"
ntp_manage_config: false
ntp_area: ""
ntp_servers:
- "0.{{ ntp_area }}.pool.ntp.org iburst"
- "1.{{ ntp_area }}.pool.ntp.org iburst"
- "2.{{ ntp_area }}.pool.ntp.org iburst"
ntp_restrict:
- "127.0.0.1"
- "::1"
...
---
ntp_daemon: ntpd
...
---
ntp_daemon: ntp
...
Ansible : Best practices
● Create a consistency in :
– Tagging
– Naming of tasks|variables|plays|roles
– Enforce the style with a pre-commit hook
● Separate tags and playbooks that have the purpose of installing and
provisioning
● Prefix role variables with role name
● Use native YAML syntax for your plays: Vertical reading is easier
● Use the run command modules (shell/command/script/raw) as a last
resort
Ansible : Best practices
● Don’t just start services -- use sanity/smoke tests
● Consider writing a module when your play is full of shell module
● Consider writing a filter when jinja hinders the readibility
Ansible
LAB
Part 2
In a playbook only and with the manual
http://docs.ansible.com/ansible/list_of_all_modules.html
or with the ansible-doc commande
Try :
● To write a playbook which check if salt is in the uri http://locahost
● Same idea but the pattern have to be different for the groups [prod] and [recette]
Ansible
LAB
Part 2
$> cat site.yml
---
- name : play 1
hosts: all
gather_facts: yes
become: yes
#vars:
# pattern: salt
Tasks:
- name: Get content page
uri:
url: http://localhost
return_content: yes
register: webpage
- name: Fail if {{ pattern }} is not in the page content
fail:
msg: "No >>> {{ pattern }} <<< in this page"
when: "pattern not in webpage.content"
#when: "ansible_hostname not in webpage.content"
...
$> cat inventory
[prod]
prod1
prod2
[recette]
rec[1:2]
[prod:vars]
pattern=pizza
[recette:vars]
pattern=salt
Ansible : Security
● Ansible can use a vaulted variable that lives in
an otherwise ‘clear text’ YAML file.
This is useful on github/lab
Ansible : Docker for CI
● « Trust is the essential reason why we need
continuous integration. »
● With Docker and a CI tool, we can do checks
on each git commit on our roles
Ansible : Docker for CI
Ansible : Docker for CI
Example : vsftpd from bertvv
The role to test
Files witness
Add a user Alice
Built PoC based on geerlingguy.apache
Ansible : Docker for CI
Bats: Bash Automated Testing System
functional tests on the container
Ansible : Docker for CI
● How it works ?
OR
syntax
tasks
idempotence
VERIFY
Instantiate a docker
container
Run functionnal
tests with BATS
Ansible : Next
● Dynamical inventories
● Modules
● Filters
Ansible
● Contact :
– cdelgehier@scalair.fr
– #ansible
– @JackNemrod
● Lab :
● https://github.com/cdelgehier/oktocampus_ansible
● Sources :
● http://blog.octo.com/administrer-son-parc-avec-du-shell
● https://viuz.com/2014/02/18/yves-morieux-bcg-6-regles-de-simplicite-au-travail/
● http://www.kianmeng.org/2017/01/using-ansible-lint-with-gits-pre-commit.html
● http://lesaventuresdeyannigdanslemondeit.blogspot.fr/2016/05/ecriture-de-filtre-ansible.html
● https://bertvv.github.io/presentation-cfgmgmtcamp2017/

Más contenido relacionado

La actualidad más candente

Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done rightDan Vaida
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them AllTim Fairweather
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestrationbcoca
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = CodeGeorg Sorst
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Keith Resar
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practicesBas Meijer
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible referencelaonap166
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to AnsibleDan Vaida
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with AnsibleAhmed AbouZaid
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster WebsiteRayed Alrashed
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?shirou wakayama
 

La actualidad más candente (20)

Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible reference
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster Website
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?
 

Similar a #OktoCampus - Workshop : An introduction to Ansible

A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of AnsibleDevOps Ltd.
 
Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)iman darabi
 
Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)Jude A. Goonawardena
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestrationPaolo Tonin
 
Automating with ansible (part a)
Automating with ansible (part a)Automating with ansible (part a)
Automating with ansible (part a)iman darabi
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modulesKris Buytaert
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient waySylvain Rayé
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
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Омские ИТ-субботники
 
Configuration Management and Salt
Configuration Management and SaltConfiguration Management and Salt
Configuration Management and Salt55020
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganCorkOpenTech
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configurationSubhas Kumar Ghosh
 
PLNOG14: Automation at Brainly - Paweł Rozlach
PLNOG14: Automation at Brainly - Paweł RozlachPLNOG14: Automation at Brainly - Paweł Rozlach
PLNOG14: Automation at Brainly - Paweł RozlachPROIDEA
 
PLNOG Automation@Brainly
PLNOG Automation@BrainlyPLNOG Automation@Brainly
PLNOG Automation@Brainlyvespian_256
 

Similar a #OktoCampus - Workshop : An introduction to Ansible (20)

A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)
 
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)
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
 
Automating with ansible (part a)
Automating with ansible (part a)Automating with ansible (part a)
Automating with ansible (part a)
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Installing AtoM with Ansible
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with Ansible
 
Puppet
PuppetPuppet
Puppet
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
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
 
Configuration Management and Salt
Configuration Management and SaltConfiguration Management and Salt
Configuration Management and Salt
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configuration
 
PLNOG14: Automation at Brainly - Paweł Rozlach
PLNOG14: Automation at Brainly - Paweł RozlachPLNOG14: Automation at Brainly - Paweł Rozlach
PLNOG14: Automation at Brainly - Paweł Rozlach
 
PLNOG Automation@Brainly
PLNOG Automation@BrainlyPLNOG Automation@Brainly
PLNOG Automation@Brainly
 

Último

Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsaqsarehman5055
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardsticksaastr
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Delhi Call girls
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyPooja Nehwal
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 

Último (20)

Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 

#OktoCampus - Workshop : An introduction to Ansible

  • 2. $> whoami ● Cédric DELGEHIER ● Ops @scalair ● Poor slide designer (sorry) ● Python lover ● Father of two wise children
  • 3. Ansible : Introduction ● How to manage the installation, the update and the configuration of all my servers ?
  • 4. Ansible : Introduction Variants : I use scripts, « for loop » or synchronized terminal
  • 5. Ansible : Introduction Where is the problem ? Scripts are : ● Hard to maintain ● Boring in heterogeneous environments ● Not idempotent natively I hope: centralized, versioned, documented, easy to read for a new colleague An idempotent operation is one that has no additional effect if it is called more than once with the same input parameters *
  • 7. Ansible : Introduction What's a provisioning framework? ● Automated setup of servers ● Configuration as code Create users Install software Generate and manipulate config files Start/stop/restart processes Set up dependencies between operations
  • 9. Ansible ● Ansible is based on Python ● Standard SSH to connect to managed servers/nodes ● Push-based system ● Agentless operation ● No central server, no special software on managed nodes ● Facts from each node used for state-full decisions ● Idempotent ConfigMgmt tool (like others) ● Extend with custom modules, use any language which can return JSON ● Inventory from various datasource, return as JSON An idempotent operation is one that has no additional effect if it is called more than once with the same input parameters
  • 10. Ansible ● Ansible is similar to Chef, Puppet or Salt ● Shared purpose – solve tasks for CfgMgmt, provisioning, deployment, etc. ● Ansible may be simplest and easiest configuration management tool to start ● Chef, Puppet, Salt are great tools as well, may be more complex to start with, steeper learning curve, etc. ● The absence of an agent allows it to manage more than servers (network or storage equipment) ● It supports managing major cloud devices (AWS, RackSpace, Digital Ocean, OpenStack) through a collection of modules which are available
  • 11. Ansible LAB Setup ● Install VirtualBox & Vagrant ● Clone the repository on github – git clone https://github.com/cdelgehier/oktocampus_ansible.git ● Run the Vagrantfile – vagrant up (or vagrant up bastion prod1 prod2 for poor laptop) ● Connect you to your own bastion – vagrant ssh bastion ● Generate your ssh key – ssh-keygen -t rsa -b 2048 ● Accept host ssh key file – ssh-keyscan prod1 prod2 rec1 rec2 > ~/.ssh/known_hosts README.md
  • 12. Ansible : Ad Hoc mode ● You don't have to create an elaborate set of tasks just to perform simple operations on your nodes ● An ad-hoc command consists of two parameters; the host group that defines on what machines to run the task against and the Ansible module to run ansible <group> -m <module> $> ansible prod -m ping $> ansible prod -m command -a 'whoami' $> ansible prod -m setup $> ansible prod -a 'hostnamectl' -m command is by default $> ansible all -a '/sbin/reboot' --forks=10 $> ansible recette -m user -a 'name=georges password=okto' $> ansible alll -m yum -a 'name=nginx state=installed' $> ansible alll -m service -a 'name=nginx state=started' $> ansible all –list-hosts $> ansible localhost -m debug -a 'var=groups.keys()'
  • 13. Ansible LAB Part 1 In Ad Hoc only and with the manual http://docs.ansible.com/ansible/list_of_all_modules.html or with the ansible-doc commande Try : ● To install a package (with yum) named epel-release then another named cowsay ● To run the command coway with moooo in argument ● Try add a user john which one is a member of the okto group ● Create a gzip archive of /etc/shadow into /tmp
  • 14. Ansible LAB Part 1 ● ansible all --become --module-name yum --args "name=epel-release state=present" ● ansible all -b -m yum -a "name=cowsay state=present" ● ansible all -a "cowsay moooo" ● ansible all -b -m group -a "name=okto" ● ansible all -b -m user -a "name=john group=okto" ● ansible all -b -m archive -a "path=/etc/shadow dest=/tmp/shadow.gz"
  • 17. Ansible : concepts ● Modules : accomplish dedicated Tasks (set values, use templates) ● Tasks : execute Module specific parameters, variables, etc. ● Variables : configuration-wide, Playbook/Roles specific vars ● Facts : gather information about the target system ● Handlers : like Tasks but usually get called by another Task ● Roles : group related Tasks, encapsulate data to accomplish Task ● Files : files directory contains files copied over to target ● Templates : Jinja2 format with placeholders to insert variables ● Vault : encrypt sensible data ● Plays : are lists of Tasks wich apply to hosts / host groups ● Playbooks : YAML formatted files orchestrate steps sequentially ● Inventory : a combination of a hosts and groups
  • 18. Ansible : concepts . |-- ansible.cfg #ansible config file |-- inventory.ini #hosts file `-- roles #roles directory `-- role1 #a role directory |-- defaults | `-- main.yml #defaults values |-- files #files directory | `-- myfile.cfg |-- handlers #handlers directory | `-- main.yml |-- tasks | `-- main.yml #task file |-- templates | `-- mytemplate.conf.j2 #template file `-- vars `-- main.yml #variable file A minimal top level directory would contain files and directories such as:
  • 19. Ansible : Inventory [prod] prod1 10.0.15.21 [recette] rec[1:2] [jira] {{ jira_ip }} Inventory files are simple text files which describe your servers IP Addresses or DNS Names, grouped by names Inventory files can take advantage of variables and enumerations
  • 20. Ansible : Playbooks ● YAML Files ● Declaratively define your configuration ● Can contain many « plays » targetting different groups Describe state (declarative)Describe what to do (imperative)
  • 21. Ansible : Playbooks --- - name : play 1 hosts: all gather_facts: yes become: yes vars: docroot: /var/www/html/ title: oktocampus body: | <h1>Hello all !</h1> <p>Is there any pizza left ? :)</p> tasks: - name: install epel repo tags: install yum: name: epel-release state: present - name: install apache httpd tags: install yum: name: httpd state: present - name: start and enable httpd tags: config service: name: httpd state: started enabled: yes - name: install packages in loop tags: install yum: name: "{{ item }}" state: present with_items: - ca-certificates - w3m - name: templating of my awesome html file tags: config template: src: index.html.j2 dest: "{{ docroot }}/index.html" owner: apache group: apache roles: - role: ntp ntp_timezone: "Europe/Paris" ntp_manage_config: true ntp_area: "fr" ntp_servers: - "0.{{ ntp_area }}.pool.ntp.org iburst" - "1.{{ ntp_area }}.pool.ntp.org iburst" - "2.{{ ntp_area }}.pool.ntp.org iburst" - "3.{{ ntp_area }}.pool.ntp.org iburst" ... All YAML files can optionally begin with --- and end with ... Define targets for this play Ansible provides many facts about the system, automatically This play needs a privilege escalation Roles are played before tasks Overwrite role's defaults Module used <!DOCTYPE html> <html> <head> <title>{{ title }}</title> </head> <body> {{ body }} # generated on {{ ansible_hostname }} OS: {{ ansible_distribution }} {{ ansible_distribution_major_version }} ip: {{ ansible_eth1.ipv4.address }} </body> </html>
  • 22. Ansible : Roles $> ansible-galaxy init ntp $> tree ntp ntp |-- defaults | `-- main.yml |-- files |-- handlers | `-- main.yml |-- meta | `-- main.yml |-- README.md |-- tasks | `-- main.yml |-- templates | |-- ntp.conf.j2 | `-- timezone.j2 |-- tests | |-- inventory | `-- test.yml `-- vars |-- Debian.yml |-- FreeBSD.yml |-- main.yml `-- RedHat.yml Creation of a role folder Variables customizable by the user Variables specific to the role Set of tests --- - name: include distribution or OS Family variable include_vars: "{{ item }}" with_first_found: - "{{ ansible_distribution }}.yml" - "{{ ansible_os_family }}.yml" - name: Ensure NTP-related packages are installed. tags: install package: name: "{{ item }}" state: present with_items: - ntp - tzdata - name: Set timezone tags: config timezone: name: "{{ ntp_timezone }}" - name: Ensure NTP is running and enabled as configured. tags: config service: name: "{{ ntp_daemon }}" state: started enabled: yes when: ntp_enabled - name: Ensure NTP is stopped and disabled as configured. tags: config service: name: "{{ ntp_daemon }}" state: stopped enabled: no when: not ntp_enabled - name: Generate ntp.conf file tags: config template: src: ntp.conf.j2 dest: /etc/ntp.conf notify: restart ntp when: ntp_manage_config ... --- ntp_enabled: true ntp_timezone: "Etc/UTC" ntp_manage_config: false ntp_area: "" ntp_servers: - "0.{{ ntp_area }}.pool.ntp.org iburst" - "1.{{ ntp_area }}.pool.ntp.org iburst" - "2.{{ ntp_area }}.pool.ntp.org iburst" ntp_restrict: - "127.0.0.1" - "::1" ... --- ntp_daemon: ntpd ... --- ntp_daemon: ntp ...
  • 23. Ansible : Best practices ● Create a consistency in : – Tagging – Naming of tasks|variables|plays|roles – Enforce the style with a pre-commit hook ● Separate tags and playbooks that have the purpose of installing and provisioning ● Prefix role variables with role name ● Use native YAML syntax for your plays: Vertical reading is easier ● Use the run command modules (shell/command/script/raw) as a last resort
  • 24. Ansible : Best practices ● Don’t just start services -- use sanity/smoke tests ● Consider writing a module when your play is full of shell module ● Consider writing a filter when jinja hinders the readibility
  • 25. Ansible LAB Part 2 In a playbook only and with the manual http://docs.ansible.com/ansible/list_of_all_modules.html or with the ansible-doc commande Try : ● To write a playbook which check if salt is in the uri http://locahost ● Same idea but the pattern have to be different for the groups [prod] and [recette]
  • 26. Ansible LAB Part 2 $> cat site.yml --- - name : play 1 hosts: all gather_facts: yes become: yes #vars: # pattern: salt Tasks: - name: Get content page uri: url: http://localhost return_content: yes register: webpage - name: Fail if {{ pattern }} is not in the page content fail: msg: "No >>> {{ pattern }} <<< in this page" when: "pattern not in webpage.content" #when: "ansible_hostname not in webpage.content" ... $> cat inventory [prod] prod1 prod2 [recette] rec[1:2] [prod:vars] pattern=pizza [recette:vars] pattern=salt
  • 27. Ansible : Security ● Ansible can use a vaulted variable that lives in an otherwise ‘clear text’ YAML file. This is useful on github/lab
  • 28. Ansible : Docker for CI ● « Trust is the essential reason why we need continuous integration. » ● With Docker and a CI tool, we can do checks on each git commit on our roles
  • 30. Ansible : Docker for CI Example : vsftpd from bertvv The role to test Files witness Add a user Alice Built PoC based on geerlingguy.apache
  • 31. Ansible : Docker for CI Bats: Bash Automated Testing System functional tests on the container
  • 32. Ansible : Docker for CI ● How it works ? OR syntax tasks idempotence VERIFY Instantiate a docker container Run functionnal tests with BATS
  • 33. Ansible : Next ● Dynamical inventories ● Modules ● Filters
  • 35. ● Contact : – cdelgehier@scalair.fr – #ansible – @JackNemrod ● Lab : ● https://github.com/cdelgehier/oktocampus_ansible ● Sources : ● http://blog.octo.com/administrer-son-parc-avec-du-shell ● https://viuz.com/2014/02/18/yves-morieux-bcg-6-regles-de-simplicite-au-travail/ ● http://www.kianmeng.org/2017/01/using-ansible-lint-with-gits-pre-commit.html ● http://lesaventuresdeyannigdanslemondeit.blogspot.fr/2016/05/ecriture-de-filtre-ansible.html ● https://bertvv.github.io/presentation-cfgmgmtcamp2017/