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

PDF
InfluxDB 101 - Concepts and Architecture | Michael DeSa | InfluxData
PPTX
Internet of things using Raspberry Pi
PPTX
Gfs vs hdfs
PPTX
Challenges and application of Internet of Things
PDF
Hardware & Software Platforms for HPC, AI and ML
PPTX
M2M systems layers and designs standardizations
PDF
My first 90 days with ClickHouse.pdf
PDF
NoSQL databases
InfluxDB 101 - Concepts and Architecture | Michael DeSa | InfluxData
Internet of things using Raspberry Pi
Gfs vs hdfs
Challenges and application of Internet of Things
Hardware & Software Platforms for HPC, AI and ML
M2M systems layers and designs standardizations
My first 90 days with ClickHouse.pdf
NoSQL databases

What's hot (20)

PDF
Apache Nifi Crash Course
PPTX
Internet of things (IoT) with Azure
PPTX
Best practices and lessons learnt from Running Apache NiFi at Renault
PDF
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
PDF
An overview of BigQuery
PPT
Google File System
PPTX
PPTX
Introduction to Warehouse-Scale Computers
PDF
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
PDF
Alphorm.com Formation VirtualBox
PPTX
Event-Driven Messaging and Actions using Apache Flink and Apache NiFi
PDF
KSQL: Streaming SQL for Kafka
PDF
Scaling up an openEHR CDR
PPTX
PDF
Dataflow with Apache NiFi
PDF
IoT & M2M.pdf
PDF
Embedded Hypervisor for ARM
PDF
Fundamentals of Apache Kafka
PDF
Streaming 101 Revisited: A Fresh Hot Take With Tyler Akidau and Dan Sotolongo...
PDF
Vector Similarity Search & Indexing Methods
Apache Nifi Crash Course
Internet of things (IoT) with Azure
Best practices and lessons learnt from Running Apache NiFi at Renault
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
An overview of BigQuery
Google File System
Introduction to Warehouse-Scale Computers
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
Alphorm.com Formation VirtualBox
Event-Driven Messaging and Actions using Apache Flink and Apache NiFi
KSQL: Streaming SQL for Kafka
Scaling up an openEHR CDR
Dataflow with Apache NiFi
IoT & M2M.pdf
Embedded Hypervisor for ARM
Fundamentals of Apache Kafka
Streaming 101 Revisited: A Fresh Hot Take With Tyler Akidau and Dan Sotolongo...
Vector Similarity Search & Indexing Methods
Ad

Viewers also liked (20)

PPTX
Automated Deployments with Ansible
PDF
Ansible for Drupal infrastructure and deployments
PDF
Ansible loves Python, Python Philadelphia meetup
PDF
Jenkins and ansible reference
PDF
Ansible Automation to Rule Them All
PPT
Ansible presentation
PPTX
Ansible: How to Get More Sleep and Require Less Coffee
PPTX
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
PDF
Ansible tips & tricks
PDF
Ansible Introduction
PDF
CS404 Pattern Recognition - Locality Preserving Projections
PPTX
Automated Deployments
PPTX
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
PPTX
Ansible presentation
PPTX
Ansible presentation
PPTX
Joget Workflow v5 Training Slides - Module 20 - Basic System Administration
PDF
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
PPTX
Introduction to Automated Deployments with Ansible
PPTX
Deploying On-Prem as SaaS: Why we go with Ansible
PPTX
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
Automated Deployments with Ansible
Ansible for Drupal infrastructure and deployments
Ansible loves Python, Python Philadelphia meetup
Jenkins and ansible reference
Ansible Automation to Rule Them All
Ansible presentation
Ansible: How to Get More Sleep and Require Less Coffee
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Ansible tips & tricks
Ansible Introduction
CS404 Pattern Recognition - Locality Preserving Projections
Automated Deployments
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Ansible presentation
Ansible presentation
Joget Workflow v5 Training Slides - Module 20 - Basic System Administration
Présentation des nouveautés de Zabbix 3.2 - Zabbix Toulouse #1 - ZUG
Introduction to Automated Deployments with Ansible
Deploying On-Prem as SaaS: Why we go with Ansible
(R)Evolutionize APM - APM in Continuous Delivery and DevOps
Ad

Similar to Ansible Overview - System Administration and Maintenance (20)

PDF
Introduction to Ansible in RHEL- RHCE.pdf
PDF
Network Automation: Ansible 101
PPT
Ansible Introduction
PDF
Ansible not only for Dummies
PPTX
Introduction to Ansible - Peter Halligan
PDF
Ansible
PDF
Configuration Management in Ansible
PDF
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
PDF
Automate with Ansible basic (2/e, English)
PDF
Automating with ansible (part a)
PPTX
Introduction to Ansible
PDF
Ansible_Basics_ppt.pdf
PDF
Ansible 202 - sysarmy
PPTX
Introduction to ansible
PPTX
Automating with ansible (Part A)
PDF
Top 50 Ansible Interview Questions And Answers in 2023.pdf
PPTX
SESSION Ansible how to deploy and push resources
PPTX
Intro to-ansible-sep7-meetup
PPTX
Ansible Network Automation session1
Introduction to Ansible in RHEL- RHCE.pdf
Network Automation: Ansible 101
Ansible Introduction
Ansible not only for Dummies
Introduction to Ansible - Peter Halligan
Ansible
Configuration Management in Ansible
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Automate with Ansible basic (2/e, English)
Automating with ansible (part a)
Introduction to Ansible
Ansible_Basics_ppt.pdf
Ansible 202 - sysarmy
Introduction to ansible
Automating with ansible (Part A)
Top 50 Ansible Interview Questions And Answers in 2023.pdf
SESSION Ansible how to deploy and push resources
Intro to-ansible-sep7-meetup
Ansible Network Automation session1

More from Jishnu P (6)

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

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.

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