SlideShare a Scribd company logo
1 of 32
Download to read offline
Introduction
CC https://www.flickr.com/photos/din_bcn/2551132104/
@orestesCA Galicia - December 2015
Orestes
Carracedo
Indenpendent Consultant
Full-Stack Developer
Est. 2005
Ansible Barcelona
Betabeers Barcelona
GDG Vigo
@OrestesCA
whoami
@orestesCA Galicia - December 2015
@orestesCA Galicia - December 2015
Introduction to Ansible
@orestesCA Galicia - December 2015
What is Ansible
SCM automation tool
agent-less
simple + powerful
@orestesCA Galicia - December 2015
What is Ansible
Versioned Environment Configuration
• Ensures consistency between environments
• Allows easily reproducible conditions
• Quicker disaster recovery
@orestesCA Galicia - December 2015
Basics
Managed Node #1
Managed Node #2
Control Machine
Inventory
ssh
@orestesCA Galicia - December 2015
$ vagrant init https://github.com/
holms/vagrant-jessie-box/releases/
download/Jessie-v0.1/Debian-jessie-
amd64-netboot.box
…
$ vagrant up
…
$ vagrant ssh-config
HostName 127.0.0.1
User vagrant
Port 2222
…
Managed Node setup
http://vagrantup.com
http://vagrantbox.es
@orestesCA Galicia - December 2015
Managed Node security credentials
$ vagrant ssh --command "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/
authorized_keys”
$ ssh vagrant@localhost -p 2222
…
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2222' (RSA) to the list
of known hosts.
…
Last login: Sun Jun 7 01:21:33 2015 from 10.0.2.2
vagrant@Debian-jessie-amd64-netboot:~$ exit
@orestesCA Galicia - December 2015
Control Machine setup
http://docs.ansible.com
$ sudo pip install paramiko PyYAML Jinja2 httplib2
$ git clone git://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ source hacking/env-setup
…
$ ansible
ansible ansible-doc ansible-galaxy ansible-
playbook ansible-pull ansible-vault
@orestesCA Galicia - December 2015
$ pip install ansible #*nix
$ brew install ansible #OS X
Inventory setup
$ export ANSIBLE_INVENTORY=~/ansible_hosts
[vagrant]
127.0.0.1:2222 foo=bar
[vagrant:vars]
ansible_ssh_user=vagrant
env=local
http://docs.ansible.com/intro_inventory.html
https://docs.ansible.com/playbooks_variables.html
Precedence: -i file
or $ANSIBLE_INVENTORY
or /etc/ansible/hosts
@orestesCA Galicia - December 2015
Ping a.k.a. Hello world
$ ansible vagrant -m ping -vvvv
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant on PORT
2222 TO 127.0.0.1
<127.0.0.1> REMOTE_MODULE ping
…
127.0.0.1 | success >> {
"changed": false,
"ping": "pong"
}
$ ansible all -m ping —vvvv
…
@orestesCA Galicia - December 2015
Random
_________________
< GATHERING FACTS >
-----------------
 ^__^
 (oo)_______
(__) )/
||----w |
|| ||
http://docs.ansible.com/faq.html#how-do-i-disable-cowsay
export ANSIBLE_NOCOWS=1
@orestesCA Galicia - December 2015
Playbooks
- hosts: vagrant
sudo: True
tasks:
- name: Install ntp
apt: pkg=ntp state=installed
$ ansible-playbook test_playbook.yml
…
GATHERING FACTS
ok: [127.0.0.1]
TASK: [Install ntp] 

changed: [127.0.0.1]
PLAY RECAP
127.0.0.1: ok=2 changed=1 unreachable=0 failed=0
test_playbook.yml
@orestesCA Galicia - December 2015
Idempotence
- hosts: vagrant
sudo: True
tasks:
- name: Install ntp
apt: pkg=ntp state=installed
$ ansible-playbook test_playbook.yml
…
GATHERING FACTS
ok: [127.0.0.1]
TASK: [Install ntp]

ok: [127.0.0.1]
PLAY RECAP
127.0.0.1: ok=2 changed=0 unreachable=0 failed=0
test_playbook.yml
@orestesCA Galicia - December 2015
Idempotence
- hosts: vagrant
sudo: True
tasks:
- name: Install ntp
apt: pkg=ntp state=installed
$ ansible-playbook test_playbook.yml
…
GATHERING FACTS
ok: [127.0.0.1]
TASK: [Install ntp]

ok: [127.0.0.1]
PLAY RECAP
127.0.0.1: ok=2 changed=0 unreachable=0 failed=0
test_playbook.yml
@orestesCA Galicia - December 2015
Facts
$ ansible vagrant -m setup
127.0.0.1 | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"10.0.2.15"
],
"ansible_all_ipv6_addresses": [
"fe80::a00:27ff:fe6b:d3e"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "12/01/2006",
"ansible_bios_version": "VirtualBox",
…
@orestesCA Galicia - December 2015
Templates, facts and variables
- hosts: vagrant

sudo: True
tasks:
- name: Write MOTD
template: src=templates/motd dest=/etc/motd
You’re now in the {{ env | upper }} environment at
{{ ansible_hostname }}
{{ ansible_distribution }} {{ansible_distribution_release }}
{{ ansible_distribution_version }}
{{ ansible_system }} {{ ansible_kernel }} {{ ansible_architecture }}
test_playbook.yml
templates/motd
You’re now in the LOCAL environment at Debian-jessie-amd64-
netboot Debian jessie 8.0 Linux 3.16.0-4-amd64 x86_64
@orestesCA Galicia - December 2015
Conditionals
- name: Enable LOCAL env prompt indicator
template: src=templates/env/local/.bash_profile
dest=~/.bash_profile
when: env == "local"
test_playbook.yml
export PS1="[$(tput setaf 2)][u@h W]$ [$(tput setaf
7)][$(tput sgr0)]"
templates/.bash_profile
[vagrant@Debian-jessie-amd64-netboot ~]$
https://docs.ansible.com/playbooks_conditionals.html
@orestesCA Galicia - December 2015
Notifications and handlers
- 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 (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
@orestesCA Galicia - December 2015
Roles
site.yml
roles/
common/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
webserver/
…
files
https://docs.ansible.com/playbooks_roles.html
https://github.com/ansible/ansible-examples
- hosts: webservers
roles:
- common
- webserver
site.yml
@orestesCA Galicia - December 2015
First steps in practice
Dependencies
Credentials
Deployment
@orestesCA Galicia - December 2015
Install dependencies
$ ansible-playbook test_playbook.yml
…
/bin/sh: 1: /usr/bin/python: not found
…
Missing Python
gather_facts: False
tasks:
- name: Install Python
raw: apt-get install python -y
- name: Gather facts after python install
setup:
- name: Write MOTD
…
test_playbook.yml
@orestesCA Galicia - December 2015
Install dependencies
$ ansible-playbook test_playbook.yml --sudo
PLAY [vagrant]

TASK: [Install Python]

ok: [127.0.0.1]
TASK: [Gather facts]
ok: [127.0.0.1]
TASK: [Write MOTD]

changed: [127.0.0.1]
PLAY RECAP
127.0.0.1: ok=3 changed=1 unreachable=0 failed=0
test_playbook.yml
@orestesCA Galicia - December 2015
Setup remote access
- name: Setup access
authorized_key: user="{{ ansible_ssh_user }}" key="{{ item }}"
with_file:
- ~/.ssh/id_rsa.pub
- /some/secure/dir/keys/admin.pub
test_playbook.yml
http://docs.ansible.com/authorized_key_module.html
$ ansible-playbook test_playbook.yml --ask-pass
SSH password:
TASK: [Setup access] 

ok: [127.0.0.1] => (item=ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQD… orestes@mjolnir.local)
…
@orestesCA Galicia - December 2015
Simple deployment
- name: Clone git repository
git: >
dest=/var/www/awesome-app
repo=https://github.com/initech/awesome-app
update=no
sudo: yes
sudo_user: www-data
register: cloned
- name: Clear cache
…
when: cloned|changed
test_playbook.yml
https://github.com/ansistrano

http://www.future500.nl/articles/2014/07/thoughts-on-deploying-with-ansible/
@orestesCA Galicia - December 2015
Quickstart
@orestesCA Galicia - December 2015
lineinfile (RegExp)
# Ensure "fav=lemonade is in section "[drinks]" in specified file
- ini_file: dest=/etc/conf section=drinks option=fav
value=lemonade mode=0600 backup=yes
- ini_file: dest=/etc/anotherconf
section=drinks
option=temperature
value=cold
backup=yes
ini_file (.ini)
Advanced deployment
http://www.ansible.com/application-deployment
http://docs.ansible.com/playbooks_delegation.html
- hosts: webservers
serial: 10
@orestesCA Galicia - December 2015
Learning from the community
https://galaxy.ansible.com
@orestesCA Galicia - December 2015
Visual inventory management
Push-button deployments
Team workflow
Role-based security
Demo
https://youtu.be/wEB7C3OAnYo
Going enterprise
@orestesCA Galicia - December 2015
EOF
___________________
< THAT’S ALL FOLKS! >
-------------------
 ^__^
 (oo)_______
(__) )/
||----w |
|| ||
@orestesCA Galicia - December 2015
Feedback welcome
orestes.ca@gmail.com
Thanks!
Galicia
@orestesCA Galicia - December 2015

More Related Content

What's hot

DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleArnaud LEMAIRE
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!Jeff Geerling
 
How Ansible Makes Automation Easy
How Ansible Makes Automation EasyHow Ansible Makes Automation Easy
How Ansible Makes Automation EasyPeter Sankauskas
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them AllTim Fairweather
 
Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Richard Donkin
 
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...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...Simplilearn
 
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDEVCON
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleMukul Malhotra
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansiblewajrcs
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible referencelaonap166
 
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
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the PipelinePuppet
 

What's hot (20)

Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!
 
Ansible - A 'crowd' introduction
Ansible - A 'crowd' introductionAnsible - A 'crowd' introduction
Ansible - A 'crowd' introduction
 
How Ansible Makes Automation Easy
How Ansible Makes Automation EasyHow Ansible Makes Automation Easy
How Ansible Makes Automation Easy
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Cyansible
CyansibleCyansible
Cyansible
 
Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)
 
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...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
 
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible reference
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Ansible
AnsibleAnsible
Ansible
 
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
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
 
Ansible Crash Course
Ansible Crash CourseAnsible Crash Course
Ansible Crash Course
 

Similar to Ansible introduction - XX Betabeers Galicia

PaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at YelpPaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at YelpNathan Handler
 
Dave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceDave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceNagios
 
Ansible, voyage au centre de l'automatisation
Ansible, voyage au centre de l'automatisationAnsible, voyage au centre de l'automatisation
Ansible, voyage au centre de l'automatisationMickael Hubert
 
Cloudstack interfaces to EC2 and GCE
Cloudstack interfaces to EC2 and GCECloudstack interfaces to EC2 and GCE
Cloudstack interfaces to EC2 and GCEShapeBlue
 
Webinar - Manage Galera Cluster with Puppet
Webinar - Manage Galera Cluster with PuppetWebinar - Manage Galera Cluster with Puppet
Webinar - Manage Galera Cluster with PuppetOlinData
 
Ansible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps MatchAnsible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps MatchJeff Geerling
 
Itb session v_memcached
Itb session v_memcachedItb session v_memcached
Itb session v_memcachedSkills Matter
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sitesYann Malet
 
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
 
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingGCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingSimon Su
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overviewprevota
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...Alexander Dean
 
Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Robert Munteanu
 
Deploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesDeploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesJimmy Angelakos
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budgetDavid Lukac
 
10 things I learned building Nomad packs
10 things I learned building Nomad packs10 things I learned building Nomad packs
10 things I learned building Nomad packsBram Vogelaar
 

Similar to Ansible introduction - XX Betabeers Galicia (20)

PaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at YelpPaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at Yelp
 
Dave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceDave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical Experience
 
Ansible, voyage au centre de l'automatisation
Ansible, voyage au centre de l'automatisationAnsible, voyage au centre de l'automatisation
Ansible, voyage au centre de l'automatisation
 
Cloudstack interfaces to EC2 and GCE
Cloudstack interfaces to EC2 and GCECloudstack interfaces to EC2 and GCE
Cloudstack interfaces to EC2 and GCE
 
Webinar - Manage Galera Cluster with Puppet
Webinar - Manage Galera Cluster with PuppetWebinar - Manage Galera Cluster with Puppet
Webinar - Manage Galera Cluster with Puppet
 
Ansible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps MatchAnsible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps Match
 
Itb session v_memcached
Itb session v_memcachedItb session v_memcached
Itb session v_memcached
 
Ansible MySQL MHA
Ansible MySQL MHAAnsible MySQL MHA
Ansible MySQL MHA
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 
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
 
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingGCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overview
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013Sling IDE Tooling @ adaptTo 2013
Sling IDE Tooling @ adaptTo 2013
 
Deploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesDeploying PostgreSQL on Kubernetes
Deploying PostgreSQL on Kubernetes
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
10 things I learned building Nomad packs
10 things I learned building Nomad packs10 things I learned building Nomad packs
10 things I learned building Nomad packs
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
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
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 

Ansible introduction - XX Betabeers Galicia

  • 2. Orestes Carracedo Indenpendent Consultant Full-Stack Developer Est. 2005 Ansible Barcelona Betabeers Barcelona GDG Vigo @OrestesCA whoami @orestesCA Galicia - December 2015
  • 3. @orestesCA Galicia - December 2015
  • 4. Introduction to Ansible @orestesCA Galicia - December 2015
  • 5. What is Ansible SCM automation tool agent-less simple + powerful @orestesCA Galicia - December 2015
  • 6. What is Ansible Versioned Environment Configuration • Ensures consistency between environments • Allows easily reproducible conditions • Quicker disaster recovery @orestesCA Galicia - December 2015
  • 7. Basics Managed Node #1 Managed Node #2 Control Machine Inventory ssh @orestesCA Galicia - December 2015
  • 8. $ vagrant init https://github.com/ holms/vagrant-jessie-box/releases/ download/Jessie-v0.1/Debian-jessie- amd64-netboot.box … $ vagrant up … $ vagrant ssh-config HostName 127.0.0.1 User vagrant Port 2222 … Managed Node setup http://vagrantup.com http://vagrantbox.es @orestesCA Galicia - December 2015
  • 9. Managed Node security credentials $ vagrant ssh --command "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/ authorized_keys” $ ssh vagrant@localhost -p 2222 … Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[localhost]:2222' (RSA) to the list of known hosts. … Last login: Sun Jun 7 01:21:33 2015 from 10.0.2.2 vagrant@Debian-jessie-amd64-netboot:~$ exit @orestesCA Galicia - December 2015
  • 10. Control Machine setup http://docs.ansible.com $ sudo pip install paramiko PyYAML Jinja2 httplib2 $ git clone git://github.com/ansible/ansible.git --recursive $ cd ./ansible $ source hacking/env-setup … $ ansible ansible ansible-doc ansible-galaxy ansible- playbook ansible-pull ansible-vault @orestesCA Galicia - December 2015 $ pip install ansible #*nix $ brew install ansible #OS X
  • 11. Inventory setup $ export ANSIBLE_INVENTORY=~/ansible_hosts [vagrant] 127.0.0.1:2222 foo=bar [vagrant:vars] ansible_ssh_user=vagrant env=local http://docs.ansible.com/intro_inventory.html https://docs.ansible.com/playbooks_variables.html Precedence: -i file or $ANSIBLE_INVENTORY or /etc/ansible/hosts @orestesCA Galicia - December 2015
  • 12. Ping a.k.a. Hello world $ ansible vagrant -m ping -vvvv <127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant on PORT 2222 TO 127.0.0.1 <127.0.0.1> REMOTE_MODULE ping … 127.0.0.1 | success >> { "changed": false, "ping": "pong" } $ ansible all -m ping —vvvv … @orestesCA Galicia - December 2015
  • 13. Random _________________ < GATHERING FACTS > ----------------- ^__^ (oo)_______ (__) )/ ||----w | || || http://docs.ansible.com/faq.html#how-do-i-disable-cowsay export ANSIBLE_NOCOWS=1 @orestesCA Galicia - December 2015
  • 14. Playbooks - hosts: vagrant sudo: True tasks: - name: Install ntp apt: pkg=ntp state=installed $ ansible-playbook test_playbook.yml … GATHERING FACTS ok: [127.0.0.1] TASK: [Install ntp] 
 changed: [127.0.0.1] PLAY RECAP 127.0.0.1: ok=2 changed=1 unreachable=0 failed=0 test_playbook.yml @orestesCA Galicia - December 2015
  • 15. Idempotence - hosts: vagrant sudo: True tasks: - name: Install ntp apt: pkg=ntp state=installed $ ansible-playbook test_playbook.yml … GATHERING FACTS ok: [127.0.0.1] TASK: [Install ntp]
 ok: [127.0.0.1] PLAY RECAP 127.0.0.1: ok=2 changed=0 unreachable=0 failed=0 test_playbook.yml @orestesCA Galicia - December 2015
  • 16. Idempotence - hosts: vagrant sudo: True tasks: - name: Install ntp apt: pkg=ntp state=installed $ ansible-playbook test_playbook.yml … GATHERING FACTS ok: [127.0.0.1] TASK: [Install ntp]
 ok: [127.0.0.1] PLAY RECAP 127.0.0.1: ok=2 changed=0 unreachable=0 failed=0 test_playbook.yml @orestesCA Galicia - December 2015
  • 17. Facts $ ansible vagrant -m setup 127.0.0.1 | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "10.0.2.15" ], "ansible_all_ipv6_addresses": [ "fe80::a00:27ff:fe6b:d3e" ], "ansible_architecture": "x86_64", "ansible_bios_date": "12/01/2006", "ansible_bios_version": "VirtualBox", … @orestesCA Galicia - December 2015
  • 18. Templates, facts and variables - hosts: vagrant
 sudo: True tasks: - name: Write MOTD template: src=templates/motd dest=/etc/motd You’re now in the {{ env | upper }} environment at {{ ansible_hostname }} {{ ansible_distribution }} {{ansible_distribution_release }} {{ ansible_distribution_version }} {{ ansible_system }} {{ ansible_kernel }} {{ ansible_architecture }} test_playbook.yml templates/motd You’re now in the LOCAL environment at Debian-jessie-amd64- netboot Debian jessie 8.0 Linux 3.16.0-4-amd64 x86_64 @orestesCA Galicia - December 2015
  • 19. Conditionals - name: Enable LOCAL env prompt indicator template: src=templates/env/local/.bash_profile dest=~/.bash_profile when: env == "local" test_playbook.yml export PS1="[$(tput setaf 2)][u@h W]$ [$(tput setaf 7)][$(tput sgr0)]" templates/.bash_profile [vagrant@Debian-jessie-amd64-netboot ~]$ https://docs.ansible.com/playbooks_conditionals.html @orestesCA Galicia - December 2015
  • 20. Notifications and handlers - 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 (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted @orestesCA Galicia - December 2015
  • 22. First steps in practice Dependencies Credentials Deployment @orestesCA Galicia - December 2015
  • 23. Install dependencies $ ansible-playbook test_playbook.yml … /bin/sh: 1: /usr/bin/python: not found … Missing Python gather_facts: False tasks: - name: Install Python raw: apt-get install python -y - name: Gather facts after python install setup: - name: Write MOTD … test_playbook.yml @orestesCA Galicia - December 2015
  • 24. Install dependencies $ ansible-playbook test_playbook.yml --sudo PLAY [vagrant]
 TASK: [Install Python]
 ok: [127.0.0.1] TASK: [Gather facts] ok: [127.0.0.1] TASK: [Write MOTD]
 changed: [127.0.0.1] PLAY RECAP 127.0.0.1: ok=3 changed=1 unreachable=0 failed=0 test_playbook.yml @orestesCA Galicia - December 2015
  • 25. Setup remote access - name: Setup access authorized_key: user="{{ ansible_ssh_user }}" key="{{ item }}" with_file: - ~/.ssh/id_rsa.pub - /some/secure/dir/keys/admin.pub test_playbook.yml http://docs.ansible.com/authorized_key_module.html $ ansible-playbook test_playbook.yml --ask-pass SSH password: TASK: [Setup access] 
 ok: [127.0.0.1] => (item=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD… orestes@mjolnir.local) … @orestesCA Galicia - December 2015
  • 26. Simple deployment - name: Clone git repository git: > dest=/var/www/awesome-app repo=https://github.com/initech/awesome-app update=no sudo: yes sudo_user: www-data register: cloned - name: Clear cache … when: cloned|changed test_playbook.yml https://github.com/ansistrano
 http://www.future500.nl/articles/2014/07/thoughts-on-deploying-with-ansible/ @orestesCA Galicia - December 2015
  • 27. Quickstart @orestesCA Galicia - December 2015 lineinfile (RegExp) # Ensure "fav=lemonade is in section "[drinks]" in specified file - ini_file: dest=/etc/conf section=drinks option=fav value=lemonade mode=0600 backup=yes - ini_file: dest=/etc/anotherconf section=drinks option=temperature value=cold backup=yes ini_file (.ini)
  • 29. Learning from the community https://galaxy.ansible.com @orestesCA Galicia - December 2015
  • 30. Visual inventory management Push-button deployments Team workflow Role-based security Demo https://youtu.be/wEB7C3OAnYo Going enterprise @orestesCA Galicia - December 2015
  • 31. EOF ___________________ < THAT’S ALL FOLKS! > ------------------- ^__^ (oo)_______ (__) )/ ||----w | || || @orestesCA Galicia - December 2015