SlideShare a Scribd company logo
Ansible Workshop
hello!
I am Arie Bregman
2
What are we going to do today?
● Learn what is Ansible
● Do automation with Ansible
● Ask the instructor many question
3
What is Ansible?
● IT Automation Tool
● Focuses on simplicity and ease-of-use
● Open Source
○ More than 4,000 contributors
○ More than 40,000 contributions
4
Why using Ansible?
● “Why not simply use shell scripts?”
● “Why specifically Ansible and not Puppet or Chef or …?”
5
Let’s install a package with a shell script
6
YUM_CMD=$(which yum) # or dnf
APT_GET_CMD=$(which apt-get)
...
if [[ ! -z $YUM_CMD ]]; then
dnf install ntpdate
elif [[ ! -z $APT_GET_CMD ]]; then
apt-get install ntpdate
elif ...
...
else
echo "error can't install package ntpdate"
exit 1;
fi
Now let’s install the same package with Ansible
7
- name: install ntpdate
package:
name: ntpdate
state: present
● Works on multiple distributions
● Readable
● Describes desired status rather than the action
This is called a
“task” in Ansible
Why specifically Ansible?
8
● Python & SSH is all you need
● Simple to use
● Agentless
● Over 3300 modules!
● Great community
Time to have fun! but first, installation
9
# Fedora, RHEL 8, CentOS 8
$ dnf install ansible -y
# For older releases, use yum instead
# Ubuntu
$ apt-get install ansible -y
# Verify you can ssh without using a password to the machine you’ll use
$ ssh x.x.x.x
# No? Then run the following
$ ssh-copy-id <user>@x.x.x.x
Inventory
11
● The hosts/servers you manage with Ansible
● Types of inventory
○ Static
○ Dynamic
● Default inventory
○ /etc/ansible/hosts
We will define a static inventory
Update you inventory
12
[remote]
x.x.x.x
$ sudo vi /etc/ansible/hosts
Let’s test it! :)
ansible remote -m ping
remote | SUCCESS => {
"changed": false,
"ping": "pong"
}
x.x.x.x [remote]
X.x.x.x ansible_user=vagrant
Or Or
Using this, you can
later reference in
Ansible multiple
servers with one
name
Write your first Playbook
13
- hosts: remote
tasks:
- name: Create the file /tmp/x
file:
path: /tmp/x
state: touch
$ vi first_task.yml
* A playbooks is a collection
plays
* A play is a collection of tasks
running on a single or multiple
hosts
Run your first Playbook
14
PLAY [remote] **************************************************
TASK [Gathering Facts] *****************************************
ok: [remote]
TASK [Create the file /tmp/x] **********************************
changed: [remote]
PLAY RECAP *****************************************************
remote : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0
$ ansible-playbook first_playbook.yml
Multiple Tasks
15
- hosts: remote
tasks:
- name: Install the package htop
become: yes
package:
name: htop
state: present
- name: install the package python-routes
become: true
package:
name: python-routes
state: present
- hosts: webservers
tasks:
- name: Install the package htop
become: yes
package:
name: htop
state: present
- hosts: dbservers
tasks:
- name: install the package python-routes
become: root
package:
name: python-routes
state: present
Playbook
play
play
Exercise #1
16
● Write a playbook which will:
○ Create the file /tmp/x
○ Create the file /tmp/y
○ Create the file /tmp/z
- hosts: [host or hosts group name]
tasks:
- name: [task name]
[module name]:
path: ...
state: ...
# Commands
ansible-playbook
What modules are there?
17
$ ansible-doc <module_name>
$ ansible-doc file
$ ansible-doc -l
● List modules
● Information on specific module
ansible-doc format
18
Module source code path
Module Description
Single option (Optional)
19
Module Author and support
Examples ==
How to use the
module
Variables
20
● Used for storing values you can reference multiple times in your
playbook, in different tasks
● It’s common to find them used in conditionals, loops, ...
- hosts: remote
vars:
file_path: /tmp/x
tasks:
- name: Create the file "{{ file_path }}"
file:
name: "{{ file_path }}"
state: touch
Loops
21
● What if I need to create 10 files or install 30 package?
- hosts: remote
tasks:
- name: Create multiple files
file:
name: "{{ item }}"
state: touch
loop:
- /tmp/a
- /tmp/b
- /tmp/c
22
PLAY [remote]
********************************************************************************************************
TASK [Gathering Facts]
************************************************************************************************
ok: [192.168.33.10]
TASK [add several users]
**************************************************************************************************
changed: [192.168.33.10] => (item=/tmp/a)
changed: [192.168.33.10] => (item=/tmp/b)
changed: [192.168.33.10] => (item=/tmp/c)
PLAY RECAP
************************************************************************************************************
192.168.33.10 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0
Privileges
23
● Some tasks can’t be executed by a regular user
○ Installing packages
○ Adding users
● The “become” directive helps with that
- hosts: remote
tasks:
- name: Install the package python
become: yes
package:
name: python
state: present
- hosts: remote
tasks:
- name: Install the package python
become: yes
become_user: luigi
file:
path: ~/stam_file
state: present
Exercise #2
24
● Write a playbook which will:
○ Add the users
■ sarah, john, grace
○ Create the directories
■ /tmp/dir1 , /tmp/dir2, /tmp/dir3
# Commands
ansible-playbook
ansible-doc -l
ansible-doc <module_name>
# Directives
loop:
become:
become_user:
- hosts: remote
tasks:
- name: blip blop
file:
...
loop:
- ...
Facts
25
ansible remote -m setup | less
...
"ansible_user_dir": "/home/vagrant",
"ansible_user_gecos": "",
"ansible_user_gid": 1000,
"ansible_user_id": "vagrant",
"ansible_user_shell": "/bin/bash",
"ansible_user_uid": 1000,
"ansible_userspace_architecture": "x86_64",
"ansible_userspace_bits": "64",
"ansible_virtualization_role": "guest",
"ansible_virtualization_type": "virtualbox",
...
Conditionals
26
● Run task only when certain condition is met
- hosts: remote
tasks:
- name: Install apache httpd
become: yes
apt:
name: apache2
state: present
when: ansible_facts['distribution'] == "Ubuntu"
Conditionals: AND
27
- hosts: remote
tasks:
- name: Install apache httpd
become: yes
apt:
name: apache2
state: present
when:
- ansible_facts['distribution'] in ['CentOS', 'RedHat']
- my_var < 6
- install_apache
Conditionals: OR
28
- hosts: remote
tasks:
- name: Install apache httpd
become: yes
apt:
name: apache2
state: present
when: ansible_facts['distribution'] == "Ubuntu" or ansible_facts['distribution'] == "Suse"
29
{{ [32, 3, 5, 121, 6, 7] | max }}
Filters
● Transformation of data
{{ [32, 3, 5, 121, 6, 7] | min }}
{{ [32, 3, 5, 121, 6, 7] | random }}
{{ some_path | dirname }}
{{ some_string | quote }}
30
- hosts: remote
tasks:
- name: Create multiple files
file:
name: "{{ item }}"
state: touch
loop: “{{ files_list | default([]) }}” What is the result of
the task?
OK? Changed?
Skipped?
● Also useful for dealing with undefined variables
Exercise #3
31
● Write a playbook which will:
○ Install the package htop only if the major version of the
operating system is 14
○ Install the package netcat only if the major version of the
operating system is 16
○ Add one random user of the following
■ [‘ed’, ‘eddy’, ‘eddie’]
# Commands
ansible-playbook
ansible-doc -l
ansible-doc <module_name>
ansible remote -m setup | less
AD-HOC
32
● Run tasks without writing playbooks
● For quick and non-repeating changes
ansible [hosts_pattern] -m [module_name] -a “[module options]”
AD-HOC Example
33
ansible remote -m file -a "name=/tmp/ad-hoc state=touch"
192.168.33.10 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/tmp/ad-hoc",
"gid": 1000,
"group": "vagrant",
"mode": "0664",
"owner": "vagrant",
"size": 0,
"state": "file",
"uid": 1000
}
Exercise #4
34
● Create locally a file with the content
○ “I came here from a far far server”
● Using ad-hoc commands:
○ Add a user called “mario”
○ Run the service “cron” (Ubuntu) or “crond” (RHEL, Fedora)
○ Copy the file you create to the remote server
# Commands
ansible-playbook
ansible-doc -l
ansible-doc <module_name>
ansible remote -m setup | less
ansible remote -m module -a “...”
ansible [hosts_pattern] -m [module_name] -a “[module options]”
Command & Shell modules
35
● “I want to run a customized script on a remote host”
● “I’m unable to find a module for what I need”
● Solution
○ command or shell module
name: Get blipblop version
become: yes
command: "rpm -q --qf %{VERSION} blipblop"
register: blipblop_rpm_version
Register Result
36
● By registering the result of a task we can “connect” between tasks
- name: Get blipblop version
become: yes
command: "rpm -q --qf %{VERSION} blipblop"
register: blipblop_rpm_version
- name: Get blipblop version
become: yes
shell: |
echo “blip blop begin”
ls -l
echo “blip blop end”
when: blipblop_rpm_version.stdout == “1.2.3”
Register: Another Example
37
● Configure an app and run it only if configuration was successful
- name: configure X app
command: configure
args:
chdir: /x_app
register: x_app_config
- name: run X app
command: run
args:
chdir: /x_app
when: x_app_config.rc == 0
Register: One More Example
38
● Run until return code is 0
- name: run some_command
command: some_command
register: result
until: result.rc == 0
retries: 5
Exercise #5
39
● Write the following playbook:
○ Download the file
https://gist.github.com/corysimmons/8b94c08421dec18bbaa4
○ If the download was successful, log the message “I managed to
download file with Ansible. So excited…”
# Commands
ansible-playbook
ansible-doc -l
ansible-doc <module_name>
ansible remote -m setup | less
ansible remote -m module -a “...”
# Directives
loop:
when:
become: become_user:
args:
until:
# Variables
{{ x }}
{{ x | default(“”) }}
Summary
40
# Commands
ansible-playbook
ansible-doc -l
ansible-doc <module_name>
ansible remote -m setup | less
ansible remote -m module -a “...”
# Variables
{{ x }}
{{ x | default(“”) }}
# Directives
loop:
when:
become:
become_user
args:
until:
Next Steps (Suggestion)
41
● Blocks
● Ansible Roles
● Dynamic Inventory
● Error Handling
● Tests
thanks!
Any questions?
You can contact me at
linkedin@abregman
42
Credits
Special thanks to all the people who made and released
these awesome resources for free:
✘ Presentation template by SlidesCarnival
✘ Photographs by Unsplash
43

More Related Content

What's hot

Mac OSX Terminal 101
Mac OSX Terminal 101Mac OSX Terminal 101
Mac OSX Terminal 101
Murugun Murugun
 
Automating with ansible (Part c)
Automating with ansible (Part c) Automating with ansible (Part c)
Automating with ansible (Part c)
iman darabi
 
HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係
Kiwamu Okabe
 
Linux Command Line
Linux Command LineLinux Command Line
Linux Command Line
Prima Yogi Loviniltra
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Common linux ubuntu commands overview
Common linux  ubuntu commands overviewCommon linux  ubuntu commands overview
Common linux ubuntu commands overview
Ameer Sameer
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
kishore1986
 
Unix Commands
Unix CommandsUnix Commands
Unix CommandsDr.Ravi
 
Haproxy - zastosowania
Haproxy - zastosowaniaHaproxy - zastosowania
Haproxy - zastosowania
Łukasz Jagiełło
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
Ahmed El-Arabawy
 
Docker & CoreOS at Utah Gophers
Docker & CoreOS at Utah GophersDocker & CoreOS at Utah Gophers
Docker & CoreOS at Utah Gophers
Josh Braegger
 
Puppet
PuppetPuppet
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
2015 bioinformatics bio_python
2015 bioinformatics bio_python2015 bioinformatics bio_python
2015 bioinformatics bio_python
Prof. Wim Van Criekinge
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
Gabor Kozma
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
Ahmed El-Arabawy
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
swtjerin4u
 

What's hot (20)

Mac OSX Terminal 101
Mac OSX Terminal 101Mac OSX Terminal 101
Mac OSX Terminal 101
 
Automating with ansible (Part c)
Automating with ansible (Part c) Automating with ansible (Part c)
Automating with ansible (Part c)
 
HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係
 
Linux Command Line
Linux Command LineLinux Command Line
Linux Command Line
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
Common linux ubuntu commands overview
Common linux  ubuntu commands overviewCommon linux  ubuntu commands overview
Common linux ubuntu commands overview
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Unix Commands
Unix CommandsUnix Commands
Unix Commands
 
Haproxy - zastosowania
Haproxy - zastosowaniaHaproxy - zastosowania
Haproxy - zastosowania
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
 
Docker & CoreOS at Utah Gophers
Docker & CoreOS at Utah GophersDocker & CoreOS at Utah Gophers
Docker & CoreOS at Utah Gophers
 
Puppet
PuppetPuppet
Puppet
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
2015 bioinformatics bio_python
2015 bioinformatics bio_python2015 bioinformatics bio_python
2015 bioinformatics bio_python
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 

Similar to Ansible for Beginners

Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
Lorin Hochstein
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
Omid Vahdaty
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
Cédric Delgehier
 
OpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on TutorialOpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on Tutorial
OpenNebula Project
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
DonghuKIM2
 
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
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
Federico Razzoli
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
Chu-Siang Lai
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
Kris Buytaert
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
StephaneFlotat1
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet
Isham Rashik
 
Using Puppet to Create a Dynamic Network - PuppetConf 2013
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
Puppet
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
Stephane Manciot
 
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
Омские ИТ-субботники
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
Ivan Serdyuk
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
bcoca
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Chu-Siang Lai
 

Similar to Ansible for Beginners (20)

Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
OpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on TutorialOpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on Tutorial
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
 
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)
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet
 
Using Puppet to Create a Dynamic Network - PuppetConf 2013
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
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
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
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
 

Recently uploaded

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Ansible for Beginners

  • 2. hello! I am Arie Bregman 2
  • 3. What are we going to do today? ● Learn what is Ansible ● Do automation with Ansible ● Ask the instructor many question 3
  • 4. What is Ansible? ● IT Automation Tool ● Focuses on simplicity and ease-of-use ● Open Source ○ More than 4,000 contributors ○ More than 40,000 contributions 4
  • 5. Why using Ansible? ● “Why not simply use shell scripts?” ● “Why specifically Ansible and not Puppet or Chef or …?” 5
  • 6. Let’s install a package with a shell script 6 YUM_CMD=$(which yum) # or dnf APT_GET_CMD=$(which apt-get) ... if [[ ! -z $YUM_CMD ]]; then dnf install ntpdate elif [[ ! -z $APT_GET_CMD ]]; then apt-get install ntpdate elif ... ... else echo "error can't install package ntpdate" exit 1; fi
  • 7. Now let’s install the same package with Ansible 7 - name: install ntpdate package: name: ntpdate state: present ● Works on multiple distributions ● Readable ● Describes desired status rather than the action This is called a “task” in Ansible
  • 8. Why specifically Ansible? 8 ● Python & SSH is all you need ● Simple to use ● Agentless ● Over 3300 modules! ● Great community
  • 9. Time to have fun! but first, installation 9 # Fedora, RHEL 8, CentOS 8 $ dnf install ansible -y # For older releases, use yum instead # Ubuntu $ apt-get install ansible -y # Verify you can ssh without using a password to the machine you’ll use $ ssh x.x.x.x # No? Then run the following $ ssh-copy-id <user>@x.x.x.x
  • 10.
  • 11. Inventory 11 ● The hosts/servers you manage with Ansible ● Types of inventory ○ Static ○ Dynamic ● Default inventory ○ /etc/ansible/hosts We will define a static inventory
  • 12. Update you inventory 12 [remote] x.x.x.x $ sudo vi /etc/ansible/hosts Let’s test it! :) ansible remote -m ping remote | SUCCESS => { "changed": false, "ping": "pong" } x.x.x.x [remote] X.x.x.x ansible_user=vagrant Or Or Using this, you can later reference in Ansible multiple servers with one name
  • 13. Write your first Playbook 13 - hosts: remote tasks: - name: Create the file /tmp/x file: path: /tmp/x state: touch $ vi first_task.yml * A playbooks is a collection plays * A play is a collection of tasks running on a single or multiple hosts
  • 14. Run your first Playbook 14 PLAY [remote] ************************************************** TASK [Gathering Facts] ***************************************** ok: [remote] TASK [Create the file /tmp/x] ********************************** changed: [remote] PLAY RECAP ***************************************************** remote : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 $ ansible-playbook first_playbook.yml
  • 15. Multiple Tasks 15 - hosts: remote tasks: - name: Install the package htop become: yes package: name: htop state: present - name: install the package python-routes become: true package: name: python-routes state: present - hosts: webservers tasks: - name: Install the package htop become: yes package: name: htop state: present - hosts: dbservers tasks: - name: install the package python-routes become: root package: name: python-routes state: present Playbook play play
  • 16. Exercise #1 16 ● Write a playbook which will: ○ Create the file /tmp/x ○ Create the file /tmp/y ○ Create the file /tmp/z - hosts: [host or hosts group name] tasks: - name: [task name] [module name]: path: ... state: ... # Commands ansible-playbook
  • 17. What modules are there? 17 $ ansible-doc <module_name> $ ansible-doc file $ ansible-doc -l ● List modules ● Information on specific module
  • 18. ansible-doc format 18 Module source code path Module Description Single option (Optional)
  • 19. 19 Module Author and support Examples == How to use the module
  • 20. Variables 20 ● Used for storing values you can reference multiple times in your playbook, in different tasks ● It’s common to find them used in conditionals, loops, ... - hosts: remote vars: file_path: /tmp/x tasks: - name: Create the file "{{ file_path }}" file: name: "{{ file_path }}" state: touch
  • 21. Loops 21 ● What if I need to create 10 files or install 30 package? - hosts: remote tasks: - name: Create multiple files file: name: "{{ item }}" state: touch loop: - /tmp/a - /tmp/b - /tmp/c
  • 22. 22 PLAY [remote] ******************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************ ok: [192.168.33.10] TASK [add several users] ************************************************************************************************** changed: [192.168.33.10] => (item=/tmp/a) changed: [192.168.33.10] => (item=/tmp/b) changed: [192.168.33.10] => (item=/tmp/c) PLAY RECAP ************************************************************************************************************ 192.168.33.10 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0
  • 23. Privileges 23 ● Some tasks can’t be executed by a regular user ○ Installing packages ○ Adding users ● The “become” directive helps with that - hosts: remote tasks: - name: Install the package python become: yes package: name: python state: present - hosts: remote tasks: - name: Install the package python become: yes become_user: luigi file: path: ~/stam_file state: present
  • 24. Exercise #2 24 ● Write a playbook which will: ○ Add the users ■ sarah, john, grace ○ Create the directories ■ /tmp/dir1 , /tmp/dir2, /tmp/dir3 # Commands ansible-playbook ansible-doc -l ansible-doc <module_name> # Directives loop: become: become_user: - hosts: remote tasks: - name: blip blop file: ... loop: - ...
  • 25. Facts 25 ansible remote -m setup | less ... "ansible_user_dir": "/home/vagrant", "ansible_user_gecos": "", "ansible_user_gid": 1000, "ansible_user_id": "vagrant", "ansible_user_shell": "/bin/bash", "ansible_user_uid": 1000, "ansible_userspace_architecture": "x86_64", "ansible_userspace_bits": "64", "ansible_virtualization_role": "guest", "ansible_virtualization_type": "virtualbox", ...
  • 26. Conditionals 26 ● Run task only when certain condition is met - hosts: remote tasks: - name: Install apache httpd become: yes apt: name: apache2 state: present when: ansible_facts['distribution'] == "Ubuntu"
  • 27. Conditionals: AND 27 - hosts: remote tasks: - name: Install apache httpd become: yes apt: name: apache2 state: present when: - ansible_facts['distribution'] in ['CentOS', 'RedHat'] - my_var < 6 - install_apache
  • 28. Conditionals: OR 28 - hosts: remote tasks: - name: Install apache httpd become: yes apt: name: apache2 state: present when: ansible_facts['distribution'] == "Ubuntu" or ansible_facts['distribution'] == "Suse"
  • 29. 29 {{ [32, 3, 5, 121, 6, 7] | max }} Filters ● Transformation of data {{ [32, 3, 5, 121, 6, 7] | min }} {{ [32, 3, 5, 121, 6, 7] | random }} {{ some_path | dirname }} {{ some_string | quote }}
  • 30. 30 - hosts: remote tasks: - name: Create multiple files file: name: "{{ item }}" state: touch loop: “{{ files_list | default([]) }}” What is the result of the task? OK? Changed? Skipped? ● Also useful for dealing with undefined variables
  • 31. Exercise #3 31 ● Write a playbook which will: ○ Install the package htop only if the major version of the operating system is 14 ○ Install the package netcat only if the major version of the operating system is 16 ○ Add one random user of the following ■ [‘ed’, ‘eddy’, ‘eddie’] # Commands ansible-playbook ansible-doc -l ansible-doc <module_name> ansible remote -m setup | less
  • 32. AD-HOC 32 ● Run tasks without writing playbooks ● For quick and non-repeating changes ansible [hosts_pattern] -m [module_name] -a “[module options]”
  • 33. AD-HOC Example 33 ansible remote -m file -a "name=/tmp/ad-hoc state=touch" 192.168.33.10 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/tmp/ad-hoc", "gid": 1000, "group": "vagrant", "mode": "0664", "owner": "vagrant", "size": 0, "state": "file", "uid": 1000 }
  • 34. Exercise #4 34 ● Create locally a file with the content ○ “I came here from a far far server” ● Using ad-hoc commands: ○ Add a user called “mario” ○ Run the service “cron” (Ubuntu) or “crond” (RHEL, Fedora) ○ Copy the file you create to the remote server # Commands ansible-playbook ansible-doc -l ansible-doc <module_name> ansible remote -m setup | less ansible remote -m module -a “...” ansible [hosts_pattern] -m [module_name] -a “[module options]”
  • 35. Command & Shell modules 35 ● “I want to run a customized script on a remote host” ● “I’m unable to find a module for what I need” ● Solution ○ command or shell module name: Get blipblop version become: yes command: "rpm -q --qf %{VERSION} blipblop" register: blipblop_rpm_version
  • 36. Register Result 36 ● By registering the result of a task we can “connect” between tasks - name: Get blipblop version become: yes command: "rpm -q --qf %{VERSION} blipblop" register: blipblop_rpm_version - name: Get blipblop version become: yes shell: | echo “blip blop begin” ls -l echo “blip blop end” when: blipblop_rpm_version.stdout == “1.2.3”
  • 37. Register: Another Example 37 ● Configure an app and run it only if configuration was successful - name: configure X app command: configure args: chdir: /x_app register: x_app_config - name: run X app command: run args: chdir: /x_app when: x_app_config.rc == 0
  • 38. Register: One More Example 38 ● Run until return code is 0 - name: run some_command command: some_command register: result until: result.rc == 0 retries: 5
  • 39. Exercise #5 39 ● Write the following playbook: ○ Download the file https://gist.github.com/corysimmons/8b94c08421dec18bbaa4 ○ If the download was successful, log the message “I managed to download file with Ansible. So excited…” # Commands ansible-playbook ansible-doc -l ansible-doc <module_name> ansible remote -m setup | less ansible remote -m module -a “...” # Directives loop: when: become: become_user: args: until: # Variables {{ x }} {{ x | default(“”) }}
  • 40. Summary 40 # Commands ansible-playbook ansible-doc -l ansible-doc <module_name> ansible remote -m setup | less ansible remote -m module -a “...” # Variables {{ x }} {{ x | default(“”) }} # Directives loop: when: become: become_user args: until:
  • 41. Next Steps (Suggestion) 41 ● Blocks ● Ansible Roles ● Dynamic Inventory ● Error Handling ● Tests
  • 42. thanks! Any questions? You can contact me at linkedin@abregman 42
  • 43. Credits Special thanks to all the people who made and released these awesome resources for free: ✘ Presentation template by SlidesCarnival ✘ Photographs by Unsplash 43