DevOps tool that automates software deployment, infrastructure provisioning, and service orchestration using YAML playbooks and powerful modules; it is agentless, uses SSH to push configuration changes to managed nodes, and supports platforms like Linux, Windows, and network devices through a simple Python-based architecture and human-readable YAML files. Ansible can be used to automate tasks across multiple servers through ad-hoc commands or reusable playbooks and its modules help with common administrative tasks like package management, user management, and service management.
10 Trends Likely to Shape Enterprise Technology in 2024
Basics of Ansible - Sahil Davawala
1.
2. DevOps - a clipped compound of "development" and "operations"
Automate the software integration, testing, deployment, and infrastructure
changes.
Improve automation and measurement of system metrics.
The best powerful automation tool which can help us in achieving everything is
ANSIBLE.
3.
4. Basics of Ansible
Usage of Ansible
Ansible without playbook i.e. through Adhoc commands
Ansible with playbook
Ansible modules
Installation of a package on multiple instances followed by a Demo.
5. It is an IT automation tool which can configure systems, deploy
software, and orchestrate more advanced IT tasks such as
continuous deployments or zero downtime rolling updates.
6. Ansible is an agent-less and uses a PUSH(SSH) approach.
It is developed by RedHat.
It is an OpenSource application.
Platforms supported are Linux & Windows.
Linux for control machine & Windows for managed nodes.
Latest version of ansible is 2.3
Reference URL : https://github.com/ansible/ansible/releases
Major companies using Ansible are Atlassian, CISCO, EA Sports, NASA, RedHat,
Twitter and many more.
7. Control Machine Requirements
Currently Ansible can be run from any machine with Python 2.6 or 2.7 installed
Managed Node Requirements(Target Host)
On the managed nodes, you need a way to communicate, which is normally SSH.
You also need Python 2.6 or later installed for the same.
8.
9. Chef/Puppet Ansible
• Needs to be installed on Agents.
• Agents pull changes from a master.
• Communication channel used is their own
(usually not SSH)
• Complicated
setup/architecture/installation
• Complicated orchestration.
• Chef uses Ruby in backend and pure Ruby
DSL for configuration.
• Puppet using Ruby in backend and uses
Puppet DSL for configuration.
• Need not be installed on Agents.
• Pushes the changes to Agents whenever
required.
• Uses SSH
• Easy installation and architecture
• Simplified orchestration.
• Ansible backed is on Python.
• Uses YAML as configuration files.
10. Installing Ansible on CentOS :
To get Ansible for CentOS 7, first ensure that the CentOS 7 EPEL repository is
installed:
sudo yum install epel-release
sudo yum update
Once the repository is installed, install Ansible with yum:
sudo yum install ansible
Installing Ansible on Ubuntu :
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
11. Run command : ansible –version
Example output :
ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
NOTE : If anyone wants to execute the playbook on a remote machine
then it is mandatory to have Python libraries installed on that remote machine.
12. Certain settings in Ansible are adjustable via a configuration file. This
configuration file is know as ANSIBLE CONFIG
Ansible allows configuration of settings via environment variables. If these
environment variables are set, they will override any setting loaded from the
configuration file.
Here is the order in which configuration file will be processed.
13. We use YAML because it is easier for humans to read and write than other common data formats like XML or JSON.
All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with ... This is part of the YAML
format and indicates the start and end of a document.
All members of a list are lines beginning at the same indentation level starting with a "- " (a dash and a space):
Example :
---
# A list of tasty fruits
fruits:
- Apple
- Orange
- Strawberry
- Mango
…
A dictionary is represented in a simple key: value form (the colon must be followed by a space):
Example :
# An employee record
martin:
name: Martin D'vloper
job: Developer
skill: Elite
14.
15. Ansible works against multiple systems in our infrastructure at a particular point
of time.
It does this by selecting portions of systems listed in Ansible’s inventory which
defaults to being saved at the location : /etc/ansible/hosts.
You can specify a different inventory file using the -i <path> option on the
command line
Example : ansible-playbook -i playbook.yml
It can be used in both commands & playbooks.
Types of inventories includes basic list, shell script, python script, advanced script
like ec2,etc.
16.
17. To ping multiple servers at a time(which are existing in inventory file) :
ansible –m ping all
For creating a new user and manipulation of existing user accounts :
ansible all -m user -a "name=foo password=<crypted password here>”
Ensure a service is started on all webservers:
ansible webservers -m service -a "name=httpd state=started"
18. Ansible adhoc commands have the limitation in complex scenarios so to overcome
this and make the automation easy & robust, playbooks were introduced.
Playbooks can be used to manage configurations and deployments to remote
machines.
Here is the example how to use a playbook.
ansible-playbook first.yml –e name=webservers1
21. The apt module manages the apt packages.
Example :
- name: Remove "foo" package.
apt:
name: foo
state: absent
- name: Install the package "foo"
apt:
name: foo
state: present
22. Installs, upgrade, removes, and lists packages and groups with the yum package
manager.
Example :
- name: install the latest version of Apache
yum:
name: httpd
state: latest
23. Installs, upgrade and removes packages using the underlying OS package
manager.
Example :
- name: install the latest version of ntpdate
package:
name: ntpdate
state: latest
24. The shell module takes the command name followed by a list of space-delimited
arguments. It is almost exactly like the command module but runs the command
through a shell (/bin/sh) on the remote node.
Example :
- name: Executing a Command Using Shell Module
shell: ls -lrt > temp.txt
The above command lists all the files in the current folder and writes that to the file i.e.
temp.txt.
25. The command module takes the command name followed by a list of space-
delimited arguments.
The given command will be executed on all selected nodes. It will not be processed
through the shell, so variables like $HOME and operations
like "<", ">", "|", ";" and "&" will not work.
Example :
- name: Executing a command using command module.
command: cat hello.txt
The above command displays the content of the file hello.txt
26. Manage user accounts and user attributes.
Example :
- user:
name: johnd
comment: "John Doe"
uid: 1040
group: admin
27. Set system’s hostname, supports most OSs/Distributions, including those using
systemd.
Note, this module does NOT modify /etc/hosts. You need to modify it yourself using
other modules like template or replace.
Example :
- hostname:
name: web01
28.
29. Ansible command using a direct agent.
Ansible command using an Inventory group.
Ansible playbook for direct host (agent)
Ansible playbook split into multiple tasks.
Ansible playbook installing a service on multiple hosts.
Notes de l'éditeur
DevOps (a clipped compound of "development" and "operations") is a software development and delivery process that emphasizes communication and collaboration between product management, software development, and operations professionals.
It seeks to automate the process of software integration, testing, deployment, and infrastructure changes by establishing a culture and environment where building, testing, and releasing software can happen rapidly, frequently, and more reliably.
And ofcourse Crest Data Systems is one of the major companies.
For Windows :
Need pywinrm on control machine(Linux)
Need PowerShell on the target machine(Windows)
Change Management -
Provisioning -
Automation -
Orchestration - It basically means the automated arrangement, coordination, and management of complex computer systems, and services.
Playbooks - Playbooks are Ansible’s configuration, deployment, and orchestration language. Playbooks are designed to be human-readable and are developed in a basic text language.
And many more….Ansible is famous because of N number of modules support they provide.