Ansible - Introduction

Stephane Manciot
Stephane ManciotResponsable BU JVM (Scala, JavaEE) - Ebiznext um Ebiznext
Ansible - Introduction



Main features
○ Automating remote system provisioning and
applications deployment
○ With no agents to install on remote systems
○ Using existing SSHd on remote system
○ Native OpenSSH for remote communication on
control machine
○ Parallel by default
○ Automation language that approaches plain english
Installation - requirements
○ Control machine requirements
● Python 2.6
● Any OS except Windows
○ Managed node requirements
● Python 2.4
Installation - control machine - source
○ From source
● $ git clone git://github.com/ansible/ansible.git
● $ cd ./ansible
● $ source ./hacking/env-setup
○ Additional python modules
● sudo easy_install pip
● sudo pip install paramiko PyYAML jinja2 httplib2
Installation - control machine - Yum
○ Latest release Via Yum
● $ sudo yum install ansible
● make rpm from source
○ $ git clone git://github.com/ansible/ansible.git
○ $ cd ./ansible
○ make rpm
○ sudo rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm
Installation - control machine - Apt
○ Latest release Via Apt
● $ sudo apt-get install software-properties-common
● $ sudo apt-add-repository ppa:ansible/ansible
● $ sudo apt-get update
● $ sudo apt-get install ansible
Installation - control machine - Pip
○ Latest release Via pip
● $ sudo easy_install pip
● $ sudo pip install ansible
Installation - control machine - Homebrew
○ Latest release Via Homebrew
● $ brew update
● $ brew install ansible
Inventory file
○ Define how ansible will interact with remote hosts
○ Define logical groups of managed nodes
○ Default location : /etc/ansible/hosts
○ INI format
Inventory file - communication variables
○ ansible_connection : local, ssh or paramiko
○ ansible_ssh_host : the name of the host to connect
to
○ ansible_ssh_port : the ssh port number if not 22
○ ansible_ssh_user : the ssh user name to use
○ ansible_ssh_pass : the ssh password to use
(insecure)
○ ansible_ssh_private_key_file : private key file used
by ssh
Inventory file - hosts and groups
localhost ansible_connection=local
[webservers]
web[1:5].example.com ansible_connection=ssh ansible_ssh_user=webadmin
[dbservers]
db[1:2].example.com ansible_connection=ssh ansible_ssh_user=dbadmin
Inventory file - group variables
[webservers]
web[1:5].example.com ansible_connection=ssh ansible_ssh_user=webadmin
[webservers:vars]
http_port=80
Inventory file - groups of groups
[atlanta]
host1
host2
[raleigh]
host2
host3
[southeast:children]
atlanta
raleigh
Inventory file - splitting out specific data
○ Define specific data using variables within YAML
files relative to the inventory file
[atlanta]
host1
host2
○ /etc/ansible/group_vars/atlanta, /etc/ansible/
host_vars/host1
---
ntp_server: acme.example.org
database_server: storage.example.org
○ /etc/ansible/group_vars/atlanta/db_settings
Patterns
○ Decide which hosts to manage
● all hosts in the inventory (all or *)
● a specific host name or group name (host1, webservers)
● wildcard configuration (192.168.1.*)
● OR configuration (host1:host2, webservers:dbservers)
● NOT configuration (webservers:dbservers:!production)
● AND configuration (webservers:dbservers:&staging)
● REGEX configuration (~(web|db).*.example.com)
● exclude hosts using limit flag (ansible-playbook site.yml
--limit datacenter2)
Vault
○ Allows keeping encrypted data in source control
○ Created encrypted files
$ ansible-vault create foo.yml
○ Editing encrypted files
$ ansible-vault edit foo.yml
○ Encrypting unencrypted files
$ ansible-vault encrypt foo.yml
○ Decrypting encrypted files
$ ansible-vault decrypt foo.yml
○ Running ad-hoc or playbook with vault
$ ansible-playbook site.yml --vault-password-file
~/.vault_pass.txt
Vagrant integration
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network :private_network, ip: “192.168.33.10"
config.vm.provision :ansible do |ansible|
ansible.inventory_path = "vagrant-inventory.ini"
ansible.playbook = "dockers.yml"
ansible.extra_vars = { user: "vagrant" }
ansible.sudo = true
ansible.limit = 'all'
end
Ad-Hoc commands
○ $ ansible {pattern} -m {module} -a “{options}” {flags}
● pattern : which hosts
● module : which ansible module (command by default)
● options : which module options
● flags : command flags
○ -u {username}: to run the command as a different user (user
account by default)
○ -f {n}: to run the command in n parallel forks (5 by default)
○ --sudo: to run the command through sudo
○ -K: to interactively prompt you for the sudo password to use
○ -U {username}: to sudo to a user other than root
○ -i {file}: inventory file to use
○ --ask-vault-pass: to specify the vault-password interactively
○ --vault-password-file {file}: to specify the latter within a file
Ad-Hoc commands - samples
○ File transfer
$ ansible all -m copy -a "src=/etc/hosts dest=/tmp/hosts"
○ Deploying from source control
$ ansible webservers -m git -a "repo=git://
foo.example.org/repo.git dest=/srv/myapp version=HEAD"
○ Managing services
$ ansible webservers -m service -a "name=httpd
state=started"
○ Gathering facts
$ ansible all -m setup
Playbook
○ Expressed in YAML language
○ Composed of one or more “plays” in a list
○ Allowing multi-machine deployments orchestration
Playbook - play
---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running
service: name=httpd state=started
handlers:
- name: restart apache
service: name=httpd state=restarted
Playbook - hosts and users
○ hosts : one or more groups or host patterns
○ remote_user : the name of the remote user account
(per play or task)
○ sudo : run tasks using sudo (per play or task)
○ sudo_user : sudo to a different user than root
Playbook - tasks
○ Are executed in order against all machines matched
by the host pattern
○ May be Included from other files
tasks:
- include: tasks/foo.yml
○ Hosts with failed tasks are taken out for the entire
playbook
○ Each task executes a module with specific options
○ Modules are idempotent in order to bring the
system to the desired state
tasks:
- name: {task name}
{module}: {options}
Playbook - handlers
○ Notifications may be triggered at the end of each
block of tasks whenever a change has been made on
the remote system
○ Handlers are referenced by name
tasks:
- name: template configuration file
template: src=template.j2 dest=/etc/foo.conf
notify:
- restart apache
…
handlers:
- name: restart apache
service: name=apache state=restarted
Playbook - roles
○ Based on a known file structure
site.yml
webservers.yml
roles/
webservers/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
…
---
- hosts: webservers
roles:
- webservers
If roles/x/tasks/main.yml exists, tasks listed therein will be added to the play

If roles/x/handlers/main.yml exists, handlers listed therein will be added to the play

If roles/x/vars/main.yml exists, variables listed therein will be added to the play

If roles/x/meta/main.yml exists, any role dependencies listed therein will be added
to the list of roles (1.3 and later)

Any copy tasks can reference files in roles/x/files/ without having to path them
relatively or absolutely

Any script tasks can reference scripts in roles/x/files/ without having to path them
relatively or absolutely

Any template tasks can reference files in roles/x/templates/ without having to path
them relatively or absolutely

Any include tasks can reference files in roles/x/tasks/ without having to path them
relatively or absolutely
Playbook - roles
○ May be applied conditionally
---
- hosts: webservers
roles:
- { role: some_role, when: "ansible_os_family ==
'RedHat'" }
○ May be applied before or after other tasks
---
- hosts: webservers
pre_tasks:
- shell: echo 'hello'
roles:
- { role: some_role }
tasks:
- shell: echo 'still busy'
post_tasks:
- shell: echo 'goodbye'
Playbook - variables
○ Define directly inline
- hosts: webservers
vars:
http_port: 80
○ Default role variables defined in {role}/defaults/
main.yml file
○ Included variables
---
- hosts: all
remote_user: root
vars:
favcolor: blue
vars_files:
- /vars/external_vars.yml
Playbook - variables - Jinja2
○ Within conditions
● failed, changed, success, skipped
- shell: /usr/bin/foo
register: result
ignore_errors: True
- debug: msg="it failed"
when: result|failed
● mandatory
{{ variable | mandatory }}
● version_compare
{{ ansible_distribution_version | version_compare('12.04',
'>=') }}
● …
○ Within templates
My amp goes to {{ max_amp_value }}
Playbook - variables - Facts
○ Information discovered from remote system
○ Frequently used in conditionals
---
- include: "Ubuntu.yml"
when: ansible_distribution == 'Ubuntu'
○ Local facts
● {file}.fact within /etc/ansible/facts.d
[general]
foo=1
bar=2
● can be accessed in a template/playbook as
{{ ansible_local.file.general.foo }}
Playbook - variables - Precedence
○ -e variables
ansible-playbook release.yml --extra-vars "version=1.23.45
other_variable=foo"
○ “most everything else”
○ variables defined in inventory
○ variables defined in facts
○ role defaults
Playbook - conditions
○ Execute task conditionally
tasks:
- shell: echo "I've got '{{ foo }}' and am not afraid
to use it!"
when: foo is defined
○ Include tasks conditionally
- include: tasks/sometasks.yml
when: "'reticulating splines' in output"
○ Execute role conditionally
- hosts: webservers
roles:
- { role: debian_stock_config, when: ansible_os_family
== 'Debian' }
Questions ?
1 von 32

Recomendados

Ansible Introduction von
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
17.6K views35 Folien
Introduction to ansible von
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
1.1K views33 Folien
Best practices for ansible von
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
6.8K views95 Folien
Ansible, best practices von
Ansible, best practicesAnsible, best practices
Ansible, best practicesBas Meijer
13.1K views44 Folien
Automating with Ansible von
Automating with AnsibleAutomating with Ansible
Automating with AnsibleRicardo Schmidt
821 views27 Folien
Ansible tips & tricks von
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
24.1K views26 Folien

Más contenido relacionado

Was ist angesagt?

Introduction to Ansible von
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
721 views19 Folien
IT Automation with Ansible von
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
15.7K views27 Folien
Ansible presentation von
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
7.1K views21 Folien
Configuration Management in Ansible von
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible Bangladesh Network Operators Group
2.3K views27 Folien
Ansible von
AnsibleAnsible
AnsibleKamil Lelonek
1.6K views11 Folien
ansible why ? von
ansible why ?ansible why ?
ansible why ?Yashar Esmaildokht
492 views62 Folien

Was ist angesagt?(20)

Introduction to Ansible von CoreStack
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
CoreStack721 views
IT Automation with Ansible von Rayed Alrashed
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
Rayed Alrashed15.7K views
Ansible presentation von Suresh Kumar
Ansible presentationAnsible presentation
Ansible presentation
Suresh Kumar7.1K views
Introduction to Ansible von Knoldus Inc.
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
Knoldus Inc.24.2K views
Ansible presentation von Kumar Y
Ansible presentationAnsible presentation
Ansible presentation
Kumar Y3.1K views
DevOps with Ansible von Swapnil Jain
DevOps with AnsibleDevOps with Ansible
DevOps with Ansible
Swapnil Jain1.8K views
Ansible roles done right von Dan Vaida
Ansible roles done rightAnsible roles done right
Ansible roles done right
Dan Vaida1.7K views
Getting started with Ansible von Ivan Serdyuk
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
Ivan Serdyuk495 views
Network Automation with Ansible von Anas
Network Automation with AnsibleNetwork Automation with Ansible
Network Automation with Ansible
Anas 15.9K views
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO... von Simplilearn
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn2.8K views

Similar a Ansible - Introduction

Installing AtoM with Ansible von
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with AnsibleArtefactual Systems - AtoM
1.8K views4 Folien
#OktoCampus - Workshop : An introduction to Ansible von
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
435 views35 Folien
Using Puppet to Create a Dynamic Network - PuppetConf 2013 von
Using Puppet to Create a Dynamic Network - PuppetConf 2013Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013Puppet
3.9K views59 Folien
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps von
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
875 views39 Folien
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017 von
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
595 views25 Folien
Virtualization and automation of library software/machines + Puppet von
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
1.2K views38 Folien

Similar a Ansible - Introduction(20)

#OktoCampus - Workshop : An introduction to Ansible von Cédric Delgehier
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
Cédric Delgehier435 views
Using Puppet to Create a Dynamic Network - PuppetConf 2013 von Puppet
Using Puppet to Create a Dynamic Network - PuppetConf 2013Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013
Puppet3.9K views
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017 von Jumping Bean
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean595 views
Virtualization and automation of library software/machines + Puppet von Omar Reygaert
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert1.2K views
Linux Commands - Cheat Sheet von Isham Rashik
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet
Isham Rashik401 views
Ansible - Swiss Army Knife Orchestration von bcoca
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
bcoca31.7K views
Introduction to containers von Nitish Jadia
Introduction to containersIntroduction to containers
Introduction to containers
Nitish Jadia122 views
Capistrano deploy Magento project in an efficient way von Sylvain Rayé
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
Sylvain Rayé4.8K views
Hadoop meet Rex(How to construct hadoop cluster with rex) von Jun Hong Kim
Hadoop meet Rex(How to construct hadoop cluster with rex)Hadoop meet Rex(How to construct hadoop cluster with rex)
Hadoop meet Rex(How to construct hadoop cluster with rex)
Jun Hong Kim2.7K views
Introduction to Ansible - (dev ops for people who hate devops) von Jude A. Goonawardena
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 - Peter Halligan von CorkOpenTech
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
CorkOpenTech108 views
Managing your Minions with Func von danhanks
Managing your Minions with FuncManaging your Minions with Func
Managing your Minions with Func
danhanks4.2K views
Tomáš Čorej: Configuration management & CFEngine3 von Jano Suchal
Tomáš Čorej: Configuration management & CFEngine3Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3
Jano Suchal947 views

Más de Stephane Manciot

Des principes de la démarche DevOps à sa mise en oeuvre von
Des principes de la démarche DevOps à sa mise en oeuvreDes principes de la démarche DevOps à sa mise en oeuvre
Des principes de la démarche DevOps à sa mise en oeuvreStephane Manciot
9.1K views56 Folien
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015 von
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Stephane Manciot
14.3K views18 Folien
DevOps avec Ansible et Docker von
DevOps avec Ansible et DockerDevOps avec Ansible et Docker
DevOps avec Ansible et DockerStephane Manciot
21.3K views37 Folien
Docker / Ansible von
Docker / AnsibleDocker / Ansible
Docker / AnsibleStephane Manciot
2.2K views22 Folien
PSUG #52 Dataflow and simplified reactive programming with Akka-streams von
PSUG #52 Dataflow and simplified reactive programming with Akka-streamsPSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streamsStephane Manciot
15.9K views34 Folien
De Maven à SBT ScalaIO 2013 von
De Maven à SBT ScalaIO 2013De Maven à SBT ScalaIO 2013
De Maven à SBT ScalaIO 2013Stephane Manciot
5.6K views38 Folien

Más de Stephane Manciot(6)

Des principes de la démarche DevOps à sa mise en oeuvre von Stephane Manciot
Des principes de la démarche DevOps à sa mise en oeuvreDes principes de la démarche DevOps à sa mise en oeuvre
Des principes de la démarche DevOps à sa mise en oeuvre
Stephane Manciot9.1K views
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015 von Stephane Manciot
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Stephane Manciot14.3K views
PSUG #52 Dataflow and simplified reactive programming with Akka-streams von Stephane Manciot
PSUG #52 Dataflow and simplified reactive programming with Akka-streamsPSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Stephane Manciot15.9K views

Último

CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T von
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TShapeBlue
38 views34 Folien
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... von
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...ShapeBlue
55 views12 Folien
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online von
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineShapeBlue
75 views19 Folien
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... von
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
37 views15 Folien
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue von
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueShapeBlue
71 views20 Folien
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
43 views35 Folien

Último(20)

CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T von ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue38 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... von ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue55 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online von ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue75 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... von ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue37 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue von ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue71 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Why and How CloudStack at weSystems - Stephan Bienek - weSystems von ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue81 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 von Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi139 views
HTTP headers that make your website go faster - devs.gent November 2023 von Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn26 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... von TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
Business Analyst Series 2023 - Week 4 Session 7 von DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray1042 views
NTGapps NTG LowCode Platform von Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu28 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue von ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue25 views
Five Things You SHOULD Know About Postman von Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue von ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue31 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows von Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software317 views

Ansible - Introduction

  • 2. Main features ○ Automating remote system provisioning and applications deployment ○ With no agents to install on remote systems ○ Using existing SSHd on remote system ○ Native OpenSSH for remote communication on control machine ○ Parallel by default ○ Automation language that approaches plain english
  • 3. Installation - requirements ○ Control machine requirements ● Python 2.6 ● Any OS except Windows ○ Managed node requirements ● Python 2.4
  • 4. Installation - control machine - source ○ From source ● $ git clone git://github.com/ansible/ansible.git ● $ cd ./ansible ● $ source ./hacking/env-setup ○ Additional python modules ● sudo easy_install pip ● sudo pip install paramiko PyYAML jinja2 httplib2
  • 5. Installation - control machine - Yum ○ Latest release Via Yum ● $ sudo yum install ansible ● make rpm from source ○ $ git clone git://github.com/ansible/ansible.git ○ $ cd ./ansible ○ make rpm ○ sudo rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm
  • 6. Installation - control machine - Apt ○ Latest release Via Apt ● $ sudo apt-get install software-properties-common ● $ sudo apt-add-repository ppa:ansible/ansible ● $ sudo apt-get update ● $ sudo apt-get install ansible
  • 7. Installation - control machine - Pip ○ Latest release Via pip ● $ sudo easy_install pip ● $ sudo pip install ansible
  • 8. Installation - control machine - Homebrew ○ Latest release Via Homebrew ● $ brew update ● $ brew install ansible
  • 9. Inventory file ○ Define how ansible will interact with remote hosts ○ Define logical groups of managed nodes ○ Default location : /etc/ansible/hosts ○ INI format
  • 10. Inventory file - communication variables ○ ansible_connection : local, ssh or paramiko ○ ansible_ssh_host : the name of the host to connect to ○ ansible_ssh_port : the ssh port number if not 22 ○ ansible_ssh_user : the ssh user name to use ○ ansible_ssh_pass : the ssh password to use (insecure) ○ ansible_ssh_private_key_file : private key file used by ssh
  • 11. Inventory file - hosts and groups localhost ansible_connection=local [webservers] web[1:5].example.com ansible_connection=ssh ansible_ssh_user=webadmin [dbservers] db[1:2].example.com ansible_connection=ssh ansible_ssh_user=dbadmin
  • 12. Inventory file - group variables [webservers] web[1:5].example.com ansible_connection=ssh ansible_ssh_user=webadmin [webservers:vars] http_port=80
  • 13. Inventory file - groups of groups [atlanta] host1 host2 [raleigh] host2 host3 [southeast:children] atlanta raleigh
  • 14. Inventory file - splitting out specific data ○ Define specific data using variables within YAML files relative to the inventory file [atlanta] host1 host2 ○ /etc/ansible/group_vars/atlanta, /etc/ansible/ host_vars/host1 --- ntp_server: acme.example.org database_server: storage.example.org ○ /etc/ansible/group_vars/atlanta/db_settings
  • 15. Patterns ○ Decide which hosts to manage ● all hosts in the inventory (all or *) ● a specific host name or group name (host1, webservers) ● wildcard configuration (192.168.1.*) ● OR configuration (host1:host2, webservers:dbservers) ● NOT configuration (webservers:dbservers:!production) ● AND configuration (webservers:dbservers:&staging) ● REGEX configuration (~(web|db).*.example.com) ● exclude hosts using limit flag (ansible-playbook site.yml --limit datacenter2)
  • 16. Vault ○ Allows keeping encrypted data in source control ○ Created encrypted files $ ansible-vault create foo.yml ○ Editing encrypted files $ ansible-vault edit foo.yml ○ Encrypting unencrypted files $ ansible-vault encrypt foo.yml ○ Decrypting encrypted files $ ansible-vault decrypt foo.yml ○ Running ad-hoc or playbook with vault $ ansible-playbook site.yml --vault-password-file ~/.vault_pass.txt
  • 17. Vagrant integration # Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network :private_network, ip: “192.168.33.10" config.vm.provision :ansible do |ansible| ansible.inventory_path = "vagrant-inventory.ini" ansible.playbook = "dockers.yml" ansible.extra_vars = { user: "vagrant" } ansible.sudo = true ansible.limit = 'all' end
  • 18. Ad-Hoc commands ○ $ ansible {pattern} -m {module} -a “{options}” {flags} ● pattern : which hosts ● module : which ansible module (command by default) ● options : which module options ● flags : command flags ○ -u {username}: to run the command as a different user (user account by default) ○ -f {n}: to run the command in n parallel forks (5 by default) ○ --sudo: to run the command through sudo ○ -K: to interactively prompt you for the sudo password to use ○ -U {username}: to sudo to a user other than root ○ -i {file}: inventory file to use ○ --ask-vault-pass: to specify the vault-password interactively ○ --vault-password-file {file}: to specify the latter within a file
  • 19. Ad-Hoc commands - samples ○ File transfer $ ansible all -m copy -a "src=/etc/hosts dest=/tmp/hosts" ○ Deploying from source control $ ansible webservers -m git -a "repo=git:// foo.example.org/repo.git dest=/srv/myapp version=HEAD" ○ Managing services $ ansible webservers -m service -a "name=httpd state=started" ○ Gathering facts $ ansible all -m setup
  • 20. Playbook ○ Expressed in YAML language ○ Composed of one or more “plays” in a list ○ Allowing multi-machine deployments orchestration
  • 21. Playbook - play --- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running service: name=httpd state=started handlers: - name: restart apache service: name=httpd state=restarted
  • 22. Playbook - hosts and users ○ hosts : one or more groups or host patterns ○ remote_user : the name of the remote user account (per play or task) ○ sudo : run tasks using sudo (per play or task) ○ sudo_user : sudo to a different user than root
  • 23. Playbook - tasks ○ Are executed in order against all machines matched by the host pattern ○ May be Included from other files tasks: - include: tasks/foo.yml ○ Hosts with failed tasks are taken out for the entire playbook ○ Each task executes a module with specific options ○ Modules are idempotent in order to bring the system to the desired state tasks: - name: {task name} {module}: {options}
  • 24. Playbook - handlers ○ Notifications may be triggered at the end of each block of tasks whenever a change has been made on the remote system ○ Handlers are referenced by name tasks: - name: template configuration file template: src=template.j2 dest=/etc/foo.conf notify: - restart apache … handlers: - name: restart apache service: name=apache state=restarted
  • 25. Playbook - roles ○ Based on a known file structure site.yml webservers.yml roles/ webservers/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/ … --- - hosts: webservers roles: - webservers If roles/x/tasks/main.yml exists, tasks listed therein will be added to the play If roles/x/handlers/main.yml exists, handlers listed therein will be added to the play If roles/x/vars/main.yml exists, variables listed therein will be added to the play If roles/x/meta/main.yml exists, any role dependencies listed therein will be added to the list of roles (1.3 and later) Any copy tasks can reference files in roles/x/files/ without having to path them relatively or absolutely Any script tasks can reference scripts in roles/x/files/ without having to path them relatively or absolutely Any template tasks can reference files in roles/x/templates/ without having to path them relatively or absolutely Any include tasks can reference files in roles/x/tasks/ without having to path them relatively or absolutely
  • 26. Playbook - roles ○ May be applied conditionally --- - hosts: webservers roles: - { role: some_role, when: "ansible_os_family == 'RedHat'" } ○ May be applied before or after other tasks --- - hosts: webservers pre_tasks: - shell: echo 'hello' roles: - { role: some_role } tasks: - shell: echo 'still busy' post_tasks: - shell: echo 'goodbye'
  • 27. Playbook - variables ○ Define directly inline - hosts: webservers vars: http_port: 80 ○ Default role variables defined in {role}/defaults/ main.yml file ○ Included variables --- - hosts: all remote_user: root vars: favcolor: blue vars_files: - /vars/external_vars.yml
  • 28. Playbook - variables - Jinja2 ○ Within conditions ● failed, changed, success, skipped - shell: /usr/bin/foo register: result ignore_errors: True - debug: msg="it failed" when: result|failed ● mandatory {{ variable | mandatory }} ● version_compare {{ ansible_distribution_version | version_compare('12.04', '>=') }} ● … ○ Within templates My amp goes to {{ max_amp_value }}
  • 29. Playbook - variables - Facts ○ Information discovered from remote system ○ Frequently used in conditionals --- - include: "Ubuntu.yml" when: ansible_distribution == 'Ubuntu' ○ Local facts ● {file}.fact within /etc/ansible/facts.d [general] foo=1 bar=2 ● can be accessed in a template/playbook as {{ ansible_local.file.general.foo }}
  • 30. Playbook - variables - Precedence ○ -e variables ansible-playbook release.yml --extra-vars "version=1.23.45 other_variable=foo" ○ “most everything else” ○ variables defined in inventory ○ variables defined in facts ○ role defaults
  • 31. Playbook - conditions ○ Execute task conditionally tasks: - shell: echo "I've got '{{ foo }}' and am not afraid to use it!" when: foo is defined ○ Include tasks conditionally - include: tasks/sometasks.yml when: "'reticulating splines' in output" ○ Execute role conditionally - hosts: webservers roles: - { role: debian_stock_config, when: ansible_os_family == 'Debian' }