SlideShare a Scribd company logo
Introduction Installation Anatomy General Workflow Some Demo
ANSIBLE
System Administration and Maintenance
P Jishnu Jaykumar
201352005@iiitvadodara.ac.in
Indian Institute of Information Technology,
Vadodara
November 29, 2016
P Jishnu Jaykumar (201352005) @IIIT Vadodara 1/50
Introduction Installation Anatomy General Workflow Some Demo
References
https://serversforhackers.com/
an-ansible-tutorial
https://serversforhackers.com/
running-ansible-2-programmatically
https://www.ansible.com/videos
https://github.com/lorin/ansiblebook#
ansible-up-and-running-code-samples
P Jishnu Jaykumar (201352005) @IIIT Vadodara 2/50
Introduction Installation Anatomy General Workflow Some Demo
Outline
1 Introduction
2 Installation
3 Ansible : Anatomy
4 Ansible : General workflow
5 Ansible : Playbooks
6 Demo Time
P Jishnu Jaykumar (201352005) @IIIT Vadodara 3/50
Introduction Installation Anatomy General Workflow Some Demo
Introduction
P Jishnu Jaykumar (201352005) @IIIT Vadodara 4/50
Introduction Installation Anatomy General Workflow Some Demo
Introduction
“Ansible is a free-software platform for configuring and
managing computers which combines multi-node soft-
ware deployment, ad hoc task execution, and configura-
tion management. It manages nodes over SSH.”
Ansible started as a simple side project in February of
2012 by Michael DeHaan, and its rapid growth has
been a pleasant surprise .
Nowadays, it’s development is looked after by Ansible
Inc. and Red Hat Inc.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 5/50
Introduction Installation Anatomy General Workflow Some Demo
Introduction continues...
It has a different approach to solving the IT infrastruc-
ture and automation issues.
You need not learn any new programming language for
automating using ansible.
It uses the existing technologies like ssh and python.
To connect to remote servers that needs to be man-
aged, ansible either uses ssh for *nix based system
and winrm(windows remote management) for windows
based systems
P Jishnu Jaykumar (201352005) @IIIT Vadodara 6/50
The official website of Ansible is www.ansible.com.
Introduction Installation Anatomy General Workflow Some Demo
Installation
P Jishnu Jaykumar (201352005) @IIIT Vadodara 7/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Installation
P Jishnu Jaykumar (201352005) @IIIT Vadodara 8/50
Repositories can be updated using sudo apt-get update command.
Introduction Installation Anatomy General Workflow Some Demo
Anatomy
P Jishnu Jaykumar (201352005) @IIIT Vadodara 9/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Anatomy
Ansible is comprised of two entities.
Inventory
Playbooks
P Jishnu Jaykumar (201352005) @IIIT Vadodara 10/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Inventory
Inventory is just a regular file located at /etc/ansible
directory with name ”hosts” (/etc/ansible/hosts).
Contains lists of hosts on which automation will be per-
formed.
Groups of hosts are delimited by [header] elements.
You can enter hostnames or ip addresses.
A hostname/ip can be a member of multiple groups.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 11/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Inventory Examples
P Jishnu Jaykumar (201352005) @IIIT Vadodara 12/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Inventory Examples
P Jishnu Jaykumar (201352005) @IIIT Vadodara 13/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Inventory Examples
P Jishnu Jaykumar (201352005) @IIIT Vadodara 14/50
Introduction Installation Anatomy General Workflow Some Demo
Hey wait !!!
Before proceeding to playbook, let’s take an
overview of how ansible works.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 15/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 16/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 17/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 18/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 19/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 20/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 21/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : General workflow
P Jishnu Jaykumar (201352005) @IIIT Vadodara 22/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
P Jishnu Jaykumar (201352005) @IIIT Vadodara 23/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbook
A playbook is the term that Ansible uses for a configu-
ration management script.
Most of your time in Ansible will be spent writing play-
books.
Ansible playbooks are written in yaml/yml files.
YAML - Yet Another Markup Language.
Let’s take an example.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 24/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbook Example
We will configure a host to run an nginx web server.
Assume that there is a [webservers] host group in the
inventory file.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 25/50
Introduction Installation Anatomy General Workflow Some Demo
True in One Place and Yes in Another
Sharp-eyed readers might have noticed that Example 1-
1 uses True in one spot in the playbook (to enable sudo)
and yes in another spot in the playbook (to update the
apt cache).
Ansible is pretty flexible on how you represent truthy
and falsey values in playbooks.
Strictly speaking, module arguments (like up-
date cache=yes ) are treated differently from values
elsewhere in playbooks (like sudo: True ).
P Jishnu Jaykumar (201352005) @IIIT Vadodara 26/50
Introduction Installation Anatomy General Workflow Some Demo
True in One Place and Yes in Another
Values elsewhere are handled by the YAML parser and
so use the YAML conventions of truthiness, which are:
YAML truthy
true , True , TRUE , yes , Yes , YES , on , On , ON ,
y , Y
YAML falsey
false , False , FALSE , no , No , NO , off , Off , OFF ,
n , N
Module arguments are passed as strings and use Ansi-
bles internal conventions, which are:
module arg truthy - yes , on , 1 , true
module arg falsey - no , off , 0 , false
According to the official Ansible documentation, use
’yes’ and ’no’ when passing arguments to ’modules’
(since thats consistent with the module documentation),
and ’True’ and ’False’ elsewhere in playbooks.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 27/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Running the Playbook
Command : ansible-playbook web-notls.yml
Output of ansible-playbook
P Jishnu Jaykumar (201352005) @IIIT Vadodara 28/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Running the Playbook (Trick)
P Jishnu Jaykumar (201352005) @IIIT Vadodara 29/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Running the Playbook (Trick)
P Jishnu Jaykumar (201352005) @IIIT Vadodara 30/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : A Look inside playbook output
You might have noticed the following lines of output
when Ansible first starts to run:
GATHERING FACTS ****************
ok: [testserver]
When Ansible starts executing a play, the first thing it
does is collect information about the server it is con-
necting to, including :
operating system is running
hostname
IP and MAC addresses of all interfaces
and so on ...
P Jishnu Jaykumar (201352005) @IIIT Vadodara 31/50
You can then use this information later on in the playbook. For example, you might need
the IP address of the machine for populating a configuration file.
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Playbooks Are YAML
Ansible playbooks are written in YAML syntax.
YAML is a file format similar in intent to JSON, but
generally easier for humans to read and write.
Before we go over the playbook, lets cover the concepts
of YAML that are most important for writing play-
books.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 32/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks YAML Basics
Start of File
YAML files are supposed to start with three dashes to
indicate the beginning of the document: - - -
However, if you forget to put those three dashes at the
top of your playbook files, Ansible wont complain.
Comments
Comments start with a number sign and apply to the
end of the line, the same as in shell scripts, Python,
and Ruby:
# This is a YAML comment
P Jishnu Jaykumar (201352005) @IIIT Vadodara 33/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks YAML Basics
Strings
In general, YAML strings do not have to be quoted,
although you can quote them if you prefer.
Even if there are spaces, you do not need to quote them.
For example, this is a string in YAML:
this is a lovely sentence
The JSON equivalent is: ”this is a lovely sentence”
There are some scenarios in Ansible where you will need
to quote strings. These typically involve the use of
{{ braces }} for variable substitution.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 34/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Booleans
YAML has a native Boolean type, and provides you
with a wide variety of strings that can be interpreted
as true or false, which we covered in True in One Place
and Yes in Another section
For example, this is a Boolean in YAML: True
The JSON equivalent is: true
P Jishnu Jaykumar (201352005) @IIIT Vadodara 35/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Lists
YAML lists are like arrays in JSON and Ruby or lists
in Python. Technically, these are called sequences in
YAML, but call them lists here to be consistent with
the official Ansible documentation.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 36/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Dictionaries
YAML dictionaries are like objects in JSON, dictionar-
ies in Python, or hashes in Ruby. Technically, these
are called mappings in YAML, but call them dictio-
naries here to be consistent with the official Ansible
documentation.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 37/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Line Folding
When writing playbooks, you will often encounter sit-
uations where you are passing many arguments to a
module.
For aesthetics, you might want to break this up across
multiple lines in your file, but you want Ansible to treat
the string as if it were a single line.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 38/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Lets take a look at our playbook from the perspective
of a YAML file.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 39/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Lets take a look at our playbook from the perspective
of a JSON file.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 40/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Standard
P Jishnu Jaykumar (201352005) @IIIT Vadodara 41/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Plays
Looking at either the YAML or JSON representation, it
should be clear that a playbook is a list of dictionaries.
Every play must contain:
A set of hosts to configure
A list of tasks to be executed on those hosts
Think of a play as the thing that connects hosts to tasks.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 42/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Plays
In addition to specifying hosts and tasks, plays also sup-
port a number of optional settings. The three common
ones are:
Every play must contain:
name - A comment that describes what the play is
about. Ansible will print this out when the play starts
to run.
sudo - If true, Ansible will run every task by sudoing
as (by default) the root user. This is useful when man-
aging Ubuntu servers, since by default you cannot SSH
as the root user (for security users).
vars - A list of variables and values.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 43/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Tasks
Tasks are like commands in shell script.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 44/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Tasks
Ansible also supports an older syntax that uses action
as the key and puts the name of the module in the value.
The preceding example also can be written as:
Every task must contain a key with the name of a mod-
ule and a value with the arguments to that module. In
the preceding example, the module name is apt and the
arguments are name=nginx update cache=yes .
These arguments tell the apt module to install the pack-
age named nginx and to update the package cache (the
equivalent of doing an apt-get update ) before installing
the package.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 45/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Modules
Modules are scripts that come packaged with Ansible
and perform some kind of action on a host.
Admittedly, thats a pretty generic description, but
theres enormous variety across Ansible modules.
The modules we use here are:
apt - Installs or removes packages using the apt package
manager.
copy - Copies a file from local machine to the hosts.
file - Sets the attribute of a file, symlink, or directory.
service - Starts, stops, or restarts a service.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 46/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks Summary
To sum up, a playbook contains one or more plays.
A play associates an unordered set of hosts with an or-
dered list of task.
Each task is associated with exactly one module.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 47/50
Introduction Installation Anatomy General Workflow Some Demo
Ansible : Playbooks
Viewing Ansible Module Documentation
Ansible ships with the ansible-doc command-line tool,
which shows documentation about modules.
Think of it as man pages for Ansible modules.
For example, to show the documentation for the service
module, run:
ansible-doc <module-name>
P Jishnu Jaykumar (201352005) @IIIT Vadodara 48/50
Ansible executes a task on a host by generating a custom script based on the module name
and arguments, and then copies this script to the host and runs it.
Introduction Installation Anatomy General Workflow Some Demo
Demo Time !!!
P Jishnu Jaykumar (201352005) @IIIT Vadodara 49/50
Introduction Installation Anatomy General Workflow Some Demo
I have been a systems engineer, systems
administrator, a senior adviser for the
Central Intelligence Agency, a solutions
consultant and a telecommunications
information systems officer.
- Edward Snowden
Thank You.
P Jishnu Jaykumar (201352005) @IIIT Vadodara 50/50

More Related Content

Viewers also liked

Viewers also liked (20)

Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
CS404 Pattern Recognition - Locality Preserving Projections
CS404   Pattern Recognition - Locality Preserving ProjectionsCS404   Pattern Recognition - Locality Preserving Projections
CS404 Pattern Recognition - Locality Preserving Projections
 
System Maintenance
System MaintenanceSystem Maintenance
System Maintenance
 
Automated Deployments
Automated DeploymentsAutomated Deployments
Automated Deployments
 
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Joget Workflow v5 Training Slides - Module 20 - Basic System Administration
Joget Workflow v5 Training Slides - Module 20 - Basic System AdministrationJoget Workflow v5 Training Slides - Module 20 - Basic System Administration
Joget Workflow v5 Training Slides - Module 20 - Basic System Administration
 
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUGPrésentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
 
Introduction to Automated Deployments with Ansible
Introduction to Automated Deployments with AnsibleIntroduction to Automated Deployments with Ansible
Introduction to Automated Deployments with Ansible
 
Deploying On-Prem as SaaS: Why we go with Ansible
Deploying On-Prem as SaaS: Why we go with AnsibleDeploying On-Prem as SaaS: Why we go with Ansible
Deploying On-Prem as SaaS: Why we go with Ansible
 
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
(R)Evolutionize APM - APM in Continuous Delivery and DevOps(R)Evolutionize APM - APM in Continuous Delivery and DevOps
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
 
The Future of System Administration
The Future of System AdministrationThe Future of System Administration
The Future of System Administration
 
Monitoring 改造計畫:流程觀點
Monitoring 改造計畫:流程觀點Monitoring 改造計畫:流程觀點
Monitoring 改造計畫:流程觀點
 
瓶頸處理九大原則 (精簡版)
瓶頸處理九大原則 (精簡版)瓶頸處理九大原則 (精簡版)
瓶頸處理九大原則 (精簡版)
 
有了 Agile,為什麼還要有 DevOps?
有了 Agile,為什麼還要有 DevOps?有了 Agile,為什麼還要有 DevOps?
有了 Agile,為什麼還要有 DevOps?
 

More from Jishnu P (6)

SinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural ImageSinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural Image
 
Breaking CAPTCHAs using ML
Breaking CAPTCHAs using MLBreaking CAPTCHAs using ML
Breaking CAPTCHAs using ML
 
Stencil computation research project presentation #1
Stencil computation research project presentation #1Stencil computation research project presentation #1
Stencil computation research project presentation #1
 
Btp 2017 presentation
Btp 2017 presentationBtp 2017 presentation
Btp 2017 presentation
 
Ir mcq-answering-system
Ir mcq-answering-systemIr mcq-answering-system
Ir mcq-answering-system
 
Cs403 Parellel Programming Travelling Salesman Problem
Cs403   Parellel Programming Travelling Salesman ProblemCs403   Parellel Programming Travelling Salesman Problem
Cs403 Parellel Programming Travelling Salesman Problem
 

Recently uploaded

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
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
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
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
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
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
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
 
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...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
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...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
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
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Ansible Overview - System Administration and Maintenance

  • 1. Introduction Installation Anatomy General Workflow Some Demo ANSIBLE System Administration and Maintenance P Jishnu Jaykumar 201352005@iiitvadodara.ac.in Indian Institute of Information Technology, Vadodara November 29, 2016 P Jishnu Jaykumar (201352005) @IIIT Vadodara 1/50
  • 2. Introduction Installation Anatomy General Workflow Some Demo References https://serversforhackers.com/ an-ansible-tutorial https://serversforhackers.com/ running-ansible-2-programmatically https://www.ansible.com/videos https://github.com/lorin/ansiblebook# ansible-up-and-running-code-samples P Jishnu Jaykumar (201352005) @IIIT Vadodara 2/50
  • 3. Introduction Installation Anatomy General Workflow Some Demo Outline 1 Introduction 2 Installation 3 Ansible : Anatomy 4 Ansible : General workflow 5 Ansible : Playbooks 6 Demo Time P Jishnu Jaykumar (201352005) @IIIT Vadodara 3/50
  • 4. Introduction Installation Anatomy General Workflow Some Demo Introduction P Jishnu Jaykumar (201352005) @IIIT Vadodara 4/50
  • 5. Introduction Installation Anatomy General Workflow Some Demo Introduction “Ansible is a free-software platform for configuring and managing computers which combines multi-node soft- ware deployment, ad hoc task execution, and configura- tion management. It manages nodes over SSH.” Ansible started as a simple side project in February of 2012 by Michael DeHaan, and its rapid growth has been a pleasant surprise . Nowadays, it’s development is looked after by Ansible Inc. and Red Hat Inc. P Jishnu Jaykumar (201352005) @IIIT Vadodara 5/50
  • 6. Introduction Installation Anatomy General Workflow Some Demo Introduction continues... It has a different approach to solving the IT infrastruc- ture and automation issues. You need not learn any new programming language for automating using ansible. It uses the existing technologies like ssh and python. To connect to remote servers that needs to be man- aged, ansible either uses ssh for *nix based system and winrm(windows remote management) for windows based systems P Jishnu Jaykumar (201352005) @IIIT Vadodara 6/50 The official website of Ansible is www.ansible.com.
  • 7. Introduction Installation Anatomy General Workflow Some Demo Installation P Jishnu Jaykumar (201352005) @IIIT Vadodara 7/50
  • 8. Introduction Installation Anatomy General Workflow Some Demo Ansible : Installation P Jishnu Jaykumar (201352005) @IIIT Vadodara 8/50 Repositories can be updated using sudo apt-get update command.
  • 9. Introduction Installation Anatomy General Workflow Some Demo Anatomy P Jishnu Jaykumar (201352005) @IIIT Vadodara 9/50
  • 10. Introduction Installation Anatomy General Workflow Some Demo Ansible : Anatomy Ansible is comprised of two entities. Inventory Playbooks P Jishnu Jaykumar (201352005) @IIIT Vadodara 10/50
  • 11. Introduction Installation Anatomy General Workflow Some Demo Ansible : Inventory Inventory is just a regular file located at /etc/ansible directory with name ”hosts” (/etc/ansible/hosts). Contains lists of hosts on which automation will be per- formed. Groups of hosts are delimited by [header] elements. You can enter hostnames or ip addresses. A hostname/ip can be a member of multiple groups. P Jishnu Jaykumar (201352005) @IIIT Vadodara 11/50
  • 12. Introduction Installation Anatomy General Workflow Some Demo Ansible : Inventory Examples P Jishnu Jaykumar (201352005) @IIIT Vadodara 12/50
  • 13. Introduction Installation Anatomy General Workflow Some Demo Ansible : Inventory Examples P Jishnu Jaykumar (201352005) @IIIT Vadodara 13/50
  • 14. Introduction Installation Anatomy General Workflow Some Demo Ansible : Inventory Examples P Jishnu Jaykumar (201352005) @IIIT Vadodara 14/50
  • 15. Introduction Installation Anatomy General Workflow Some Demo Hey wait !!! Before proceeding to playbook, let’s take an overview of how ansible works. P Jishnu Jaykumar (201352005) @IIIT Vadodara 15/50
  • 16. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 16/50
  • 17. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 17/50
  • 18. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 18/50
  • 19. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 19/50
  • 20. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 20/50
  • 21. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 21/50
  • 22. Introduction Installation Anatomy General Workflow Some Demo Ansible : General workflow P Jishnu Jaykumar (201352005) @IIIT Vadodara 22/50
  • 23. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks P Jishnu Jaykumar (201352005) @IIIT Vadodara 23/50
  • 24. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbook A playbook is the term that Ansible uses for a configu- ration management script. Most of your time in Ansible will be spent writing play- books. Ansible playbooks are written in yaml/yml files. YAML - Yet Another Markup Language. Let’s take an example. P Jishnu Jaykumar (201352005) @IIIT Vadodara 24/50
  • 25. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbook Example We will configure a host to run an nginx web server. Assume that there is a [webservers] host group in the inventory file. P Jishnu Jaykumar (201352005) @IIIT Vadodara 25/50
  • 26. Introduction Installation Anatomy General Workflow Some Demo True in One Place and Yes in Another Sharp-eyed readers might have noticed that Example 1- 1 uses True in one spot in the playbook (to enable sudo) and yes in another spot in the playbook (to update the apt cache). Ansible is pretty flexible on how you represent truthy and falsey values in playbooks. Strictly speaking, module arguments (like up- date cache=yes ) are treated differently from values elsewhere in playbooks (like sudo: True ). P Jishnu Jaykumar (201352005) @IIIT Vadodara 26/50
  • 27. Introduction Installation Anatomy General Workflow Some Demo True in One Place and Yes in Another Values elsewhere are handled by the YAML parser and so use the YAML conventions of truthiness, which are: YAML truthy true , True , TRUE , yes , Yes , YES , on , On , ON , y , Y YAML falsey false , False , FALSE , no , No , NO , off , Off , OFF , n , N Module arguments are passed as strings and use Ansi- bles internal conventions, which are: module arg truthy - yes , on , 1 , true module arg falsey - no , off , 0 , false According to the official Ansible documentation, use ’yes’ and ’no’ when passing arguments to ’modules’ (since thats consistent with the module documentation), and ’True’ and ’False’ elsewhere in playbooks. P Jishnu Jaykumar (201352005) @IIIT Vadodara 27/50
  • 28. Introduction Installation Anatomy General Workflow Some Demo Ansible : Running the Playbook Command : ansible-playbook web-notls.yml Output of ansible-playbook P Jishnu Jaykumar (201352005) @IIIT Vadodara 28/50
  • 29. Introduction Installation Anatomy General Workflow Some Demo Ansible : Running the Playbook (Trick) P Jishnu Jaykumar (201352005) @IIIT Vadodara 29/50
  • 30. Introduction Installation Anatomy General Workflow Some Demo Ansible : Running the Playbook (Trick) P Jishnu Jaykumar (201352005) @IIIT Vadodara 30/50
  • 31. Introduction Installation Anatomy General Workflow Some Demo Ansible : A Look inside playbook output You might have noticed the following lines of output when Ansible first starts to run: GATHERING FACTS **************** ok: [testserver] When Ansible starts executing a play, the first thing it does is collect information about the server it is con- necting to, including : operating system is running hostname IP and MAC addresses of all interfaces and so on ... P Jishnu Jaykumar (201352005) @IIIT Vadodara 31/50 You can then use this information later on in the playbook. For example, you might need the IP address of the machine for populating a configuration file.
  • 32. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Playbooks Are YAML Ansible playbooks are written in YAML syntax. YAML is a file format similar in intent to JSON, but generally easier for humans to read and write. Before we go over the playbook, lets cover the concepts of YAML that are most important for writing play- books. P Jishnu Jaykumar (201352005) @IIIT Vadodara 32/50
  • 33. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks YAML Basics Start of File YAML files are supposed to start with three dashes to indicate the beginning of the document: - - - However, if you forget to put those three dashes at the top of your playbook files, Ansible wont complain. Comments Comments start with a number sign and apply to the end of the line, the same as in shell scripts, Python, and Ruby: # This is a YAML comment P Jishnu Jaykumar (201352005) @IIIT Vadodara 33/50
  • 34. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks YAML Basics Strings In general, YAML strings do not have to be quoted, although you can quote them if you prefer. Even if there are spaces, you do not need to quote them. For example, this is a string in YAML: this is a lovely sentence The JSON equivalent is: ”this is a lovely sentence” There are some scenarios in Ansible where you will need to quote strings. These typically involve the use of {{ braces }} for variable substitution. P Jishnu Jaykumar (201352005) @IIIT Vadodara 34/50
  • 35. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Booleans YAML has a native Boolean type, and provides you with a wide variety of strings that can be interpreted as true or false, which we covered in True in One Place and Yes in Another section For example, this is a Boolean in YAML: True The JSON equivalent is: true P Jishnu Jaykumar (201352005) @IIIT Vadodara 35/50
  • 36. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Lists YAML lists are like arrays in JSON and Ruby or lists in Python. Technically, these are called sequences in YAML, but call them lists here to be consistent with the official Ansible documentation. P Jishnu Jaykumar (201352005) @IIIT Vadodara 36/50
  • 37. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Dictionaries YAML dictionaries are like objects in JSON, dictionar- ies in Python, or hashes in Ruby. Technically, these are called mappings in YAML, but call them dictio- naries here to be consistent with the official Ansible documentation. P Jishnu Jaykumar (201352005) @IIIT Vadodara 37/50
  • 38. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Line Folding When writing playbooks, you will often encounter sit- uations where you are passing many arguments to a module. For aesthetics, you might want to break this up across multiple lines in your file, but you want Ansible to treat the string as if it were a single line. P Jishnu Jaykumar (201352005) @IIIT Vadodara 38/50
  • 39. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Lets take a look at our playbook from the perspective of a YAML file. P Jishnu Jaykumar (201352005) @IIIT Vadodara 39/50
  • 40. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Lets take a look at our playbook from the perspective of a JSON file. P Jishnu Jaykumar (201352005) @IIIT Vadodara 40/50
  • 41. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Standard P Jishnu Jaykumar (201352005) @IIIT Vadodara 41/50
  • 42. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Plays Looking at either the YAML or JSON representation, it should be clear that a playbook is a list of dictionaries. Every play must contain: A set of hosts to configure A list of tasks to be executed on those hosts Think of a play as the thing that connects hosts to tasks. P Jishnu Jaykumar (201352005) @IIIT Vadodara 42/50
  • 43. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Plays In addition to specifying hosts and tasks, plays also sup- port a number of optional settings. The three common ones are: Every play must contain: name - A comment that describes what the play is about. Ansible will print this out when the play starts to run. sudo - If true, Ansible will run every task by sudoing as (by default) the root user. This is useful when man- aging Ubuntu servers, since by default you cannot SSH as the root user (for security users). vars - A list of variables and values. P Jishnu Jaykumar (201352005) @IIIT Vadodara 43/50
  • 44. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Tasks Tasks are like commands in shell script. P Jishnu Jaykumar (201352005) @IIIT Vadodara 44/50
  • 45. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Tasks Ansible also supports an older syntax that uses action as the key and puts the name of the module in the value. The preceding example also can be written as: Every task must contain a key with the name of a mod- ule and a value with the arguments to that module. In the preceding example, the module name is apt and the arguments are name=nginx update cache=yes . These arguments tell the apt module to install the pack- age named nginx and to update the package cache (the equivalent of doing an apt-get update ) before installing the package. P Jishnu Jaykumar (201352005) @IIIT Vadodara 45/50
  • 46. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Modules Modules are scripts that come packaged with Ansible and perform some kind of action on a host. Admittedly, thats a pretty generic description, but theres enormous variety across Ansible modules. The modules we use here are: apt - Installs or removes packages using the apt package manager. copy - Copies a file from local machine to the hosts. file - Sets the attribute of a file, symlink, or directory. service - Starts, stops, or restarts a service. P Jishnu Jaykumar (201352005) @IIIT Vadodara 46/50
  • 47. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Summary To sum up, a playbook contains one or more plays. A play associates an unordered set of hosts with an or- dered list of task. Each task is associated with exactly one module. P Jishnu Jaykumar (201352005) @IIIT Vadodara 47/50
  • 48. Introduction Installation Anatomy General Workflow Some Demo Ansible : Playbooks Viewing Ansible Module Documentation Ansible ships with the ansible-doc command-line tool, which shows documentation about modules. Think of it as man pages for Ansible modules. For example, to show the documentation for the service module, run: ansible-doc <module-name> P Jishnu Jaykumar (201352005) @IIIT Vadodara 48/50 Ansible executes a task on a host by generating a custom script based on the module name and arguments, and then copies this script to the host and runs it.
  • 49. Introduction Installation Anatomy General Workflow Some Demo Demo Time !!! P Jishnu Jaykumar (201352005) @IIIT Vadodara 49/50
  • 50. Introduction Installation Anatomy General Workflow Some Demo I have been a systems engineer, systems administrator, a senior adviser for the Central Intelligence Agency, a solutions consultant and a telecommunications information systems officer. - Edward Snowden Thank You. P Jishnu Jaykumar (201352005) @IIIT Vadodara 50/50