You are on page 1of 33

Ansible For DevOps

Guide :-
Dr. Sudheep Elayidom M
By :-
Manish Kumar Chaudhary
(12170041), CS-A ,S8
Traditional Software development models

• Waterfall model
• Agile model

Challenges in traditional approach


• The development and operation team worked in complete isolation.
• Testing and Deployment were isolated activities done after design-
build. Hence they consumed more time than actual build cycles.
• Manual code deployment leads to human errors in production.
• Coding & operation teams have their separate timelines and are not
in synch causing further delays.
What is DevOps
What is DevOps
• DevOps (a combination of development and operations) is a
software development method that stresses communication,
collaboration and integration between software developers and
information technology (IT) operation professionals.

• DevOps is an approach based on agile and lean principles in which


business owners, development, operations, and quality assurance
team collaborate to deliver software in a continuous stable manner.

• DevOps is a culture that promotes better working relationship


within the company

• DevOps is a set of practices that provides rapid, reliable software


delivery
Do we really need DevOps
• Developers always want to deliver changes as soon as possible.

• Operations want reliability and stability.

• DevOps break down the walls between development and operations


team, unifying development to operations for better, faster outcomes.
DevOps Phases and Tools
• Integration is the heart of DevOps
How is DevOps different from traditional IT
Relationship between DevOps and Automation
• Here's how DevOps and automation are related. DevOps is not just
automation, there's more to it. Conversely, automation is not
exclusively used by "DevOps people". A lot of automation was taking
place in IT before DevOps came around.
What is Ansible


Ansible is an open-source configuration management and
provisioning tool, similar to Chef, Puppet or Salt.

It uses SSH to connect to servers and run the configured
Tasks. Ansible lets you control and configure nodes from a
single machine.

What makes it different from other management software is
that Ansible uses SSH infrastructure.
Why Ansible
● No Agent- As long as the box can be ssh’d into and it has python,
it can be configured with Ansible.
● Idempotent- Ansible’s whole architecture is structured around the
concept of idempotency. The core idea here is that you only do
things if they are needed and that things are repeatable without
side effects.
● Declarative Not Procedural- Other configuration tools tend to be
procedural do this and then do that and so on. Ansible works by
you writing a description of the state of the machine that you want
and then it takes steps to fulfill that description.
● Tiny Learning Curve- Ansible is quite easy to learn. It doesn’t
require any extra knowledge.
Architecture of Ansible

disparate
Inventory

The Inventory is a description of the nodes that can be accessed


by Ansible. By default, the Inventory is described by a
configuration file, whose default location is in./etc/ansible/hosts
The configuration file lists either the IP address or hostname of
each node that is accessible by Ansible.
Every host is assigned to a group such as web servers, db
servers etc. The inventory file can be in one of many formats
such as yaml, INI etc
Example of an Inventory file

mail.example.com

[webservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com
Playbook

Playbooks are simple YAML files. These files are descriptions of


the desired state of your systems. Ansible then does the hard
work of getting your systems to that state no matter what state
they are currently in. Playbooks make your installations,
upgrades and day-to-day management repeatable and reliable.
Playbooks are simple to write and maintain. Playbooks are
written in a natural language so they are very easy to evolve and
edit.
Playbook contains Plays.
Plays contain tasks.
tasks call modules.
Example of an ansible playbook

---
- hosts: webservers
- tasks:
- name: ensure apache is at the latest version
yum: name=httpd state=latest
- name: ensure apache is running
service: name=httpd state=started enabled=yes
Modules

There are over 1000 modules provided by Ansible to automate


every part of the environment. Modules are like plugins that do
the actual work in Ansible, they are what gets executed in each
playbook task.
Each module is mostly standalone and can be written in a
standard scripting language (such as Python, Perl, Ruby, Bash,
etc.). One of the guiding properties of modules is idempotency,
which means that even if an operation is repeated multiple times,
it will always place the system into the same state.
Example of Modules

There are lots of modules such as :


Service, file, copy, firewalld,lvol,debug etc.

Any Module can be used as :

ansible 127.0.0.1 -m service -a "name=httpd state=started"


ansible localhost -m ping
Roles
Roles are a way to group tasks together into one container. We
could have a role for setting up MySQL, another one for
configuring iptables etc.
Roles makes it easy to configure hosts. Any role can be
performed on any host or group of hosts such as:
#ansible-galaxy init roles_name
Eg: ansible-galaxy init apache
- hosts: all
roles:
- role_1
- role_2
Roles Directory Structure
Configuration file
• Describes how to control Ansible settings.
• Default location :- /etc/ansible/ansible.cfg
• Certain settings in Ansible are adjustable via a configuration file
(ansible.cfg). The stock configuration should be sufficient for most
users, but there may be reasons you would want to change them.
• It should be available in current working directory
Master-Slave Model

• Control Node acts as Master


• Managed Nodes act as Slave
• Details of managed node is stored in Inventory.
• Operations to be performed on managed nodes are specified in
playbook.
How does Ansible Work
• Ansible works by connecting to your nodes and pushing out small
programs, called "Ansible modules" to them. Ansible then executes
these modules (over SSH by default), and removes them when
finished. Your library of modules can reside on any machine, and
there are no servers, daemons, or databases required.
Ansible -implementation

• Two ways to implement


1. Ad-hoc command - with the help of ad-hoc commands.
2. Playbook – with the help of YAML program file.

Deployment of Web server


• Ad-hoc command :-
[install server]
#ansible group_name/all -m package –a “name=http state=installed”
[copy file]
#ansible group_name/all –m copy –a “src=web.html
dest=/var/www/html/index.html”
[start service]
#ansible group_name/all –m service –a “name=httpd state=started”
Deployment of Web server
-> Program file(webserver.yml)
- hosts: group_name
- tasks:
- package:
name: “httpd”
state: installed
- copy:
src: “web.html”
dest: “/var/www/html/index.html”
- service:
name: “httpd”
state: started

#ansible-playbook webserver.yml
Ansible Use Cases

● Provisioning
● Configuration Management
● App Deployment
● Continuous Delivery
● Security & Compliance
● Orchestration
Configuration Management with Ansible
Ansible is the simplest solution for configuring the nodes. It’s designed
to be minimal in nature, consistent, secure and highly reliable. Any
developer, tester or IT manager can easily configure nodes. Any IT
person can write playbooks easily.
Ansible configurations are simple data descriptions of your
infrastructure (human readable) ensuring everyone on your team will be
able to understand the meaning of each configuration task.
Ansible requires nothing more than a password or SSH key in order to
start managing systems and can start managing them without installing
any agent software.
Companies that are using Ansible
Installation Guide
• Control Node Requirements
- Python 2 (version 2.7) or Python 3 (versions 3.5 and higher)
- Base os
Red Hat, Debian, CentOS, macOS,Ubuntu
• Managed Node Requirements
- Python 2 (version 2.7) or Python 3 (versions 3.5 and higher)
- supports communication through SSH(SFTP)
• Installation
for RHEL and CentOS
- sudo yum install ansible
for Ubuntu
- sudo apt install software-properties-common
- sudo apt-add-repository - -yes - -update ppa:ansible/ansible
- sudo apt install ansible
DEMO
Conclusion

Discussed recent trending software development methodology DevOps


and use of ansible tools for configuration management. Configuration
management and server deployment is a major task in successful
delivery of product for an IT Company. Ansible tool uses push into
methodology for configuration management and server deployment.
Future Scope
Ansible tool is supported on most of operating system excluding
Windows operating system. There are networking issues for
deployment of servers on docker based operating system.
References
1.docs.ansible.com
2. Ansible for DevOps –Jeff Geerling
ThankYou

You might also like