Deploying by Ansible
Deploying by Ansible
Deploying By Ansible
Ansible Inventory
An inventory defines a collection of hosts that Ansible will manage.
Host inventories can be defined in two different ways
o Static Host Inventory
A static host inventory can be defined by a text file
o Dynamic Host Inventory
A dynamic host inventory can be generated by a script
or other program as needed, using external information
providers.
Ansible Managed hosts can be managed with following ways
o Individual
o It can assign to groups, which can be managed collectively.
o Groups can contain child groups.
o Hosts can be members of multiple groups.
Note – Ansible has default 2 group “all and ungrouped”, where all group
will show list of all managed host and ungrouped will show the managed
host which is not a part of any group
Create Inventory
# cat /etc/ansible/hosts | tail -20
Host Patterning
mumbairegion:canadaregion:- It will show all the host which are
member of these two groups, but remember it will not show the
repeated host name either one host will be member of multiple host
group.
“mumbairegion:&canadaregion” - Here & is for intersection means
it will only shows those host which is only repeated in both host
group
Deploying By Ansible
Ansible Infrastructure
While communicating managed host, we can connect by using
password or without password.
And we can use root or local user both to connect with managed
host
Control Node
# ansible 192.168.0.105 -u devops --become -m setup
Ansible Configuration
Ansible has global configuration file as /etc/ansible/ansible.conf.
[defaults]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[accelerate]
[selinux]
[colors]
$ ansible --version
ask_pass = True
Note: if using SSH keys for authentication, it’s probably not needed to
change this setting
ask_sudo_pass = True
host_key_checking = True
inventory= /home/linux2cloud/ansible/inventory
Ansible Module
Modules are programs that Ansible uses to perform operations on
managed hosts. They are ready-to-use tools designed to perform
specific operations. Modules can be executed from the ansible
command line or used in playbooks to execute tasks.
Ansible comes packaged with over 200 modules available for use.
These prepackaged modules can be used to perform a wide range of
tasks, such as cloud, user, package, and service management.
There are three types of Ansible modules
o Core
o Extras
o Custom modules
Core Module
Core modules are included with Ansible and are written and
maintained by the Ansible development team. Core modules are the
most important modules and are used for common administration
tasks.
Custom Module
Custom modules are modules developed by end users and not
shipped by Ansible. If a module does not already exist for a task, an
administrator can write a new module to implement it.
Module categories
For better organization and management, Ansible modules are
grouped into the following.
Functional categories. On Linux systems, modules are installed in
the /usr/lib/python<version>/site-packages/ansible/modules/.
o Cloud
o Clustering
o Commands
o Database
o Files
Deploying By Ansible
o Inventory
o Messaging
o Monitoring
o Network
o Notification
o Packaging
o Source Control
o System
o Utilities
o Web Infrastructure
o Windows
Ansible-doc
The ansible-doc command also offers a -s (or --snippet) option,
which produces example output that can serve as a model for how
to use a particular module in a playbook. This output can serve as a
starter template which can be included in a playbook to implement
the module for task execution.
# ansible-doc –l
# ansible-doc –s yum
# ansible-doc yum
METADATA Section
The ansible-doc documentation for the module is expected to
specify who maintains that module in the upstream Ansible
community, and what its development status is. This is indicated in
the METADATA section at the end of the output of ansible-doc for
that module.
o removed: The module has been removed from the release, but
a stub exists for documentation purposes to help former users
migrate to new modules.
o curated
Modules submitted and maintained by partners or
companies in the community. Maintainers of these
modules must watch for any issues reported or pull
requests raised against the module.
Upstream "core" developers review proposed changes
to curated modules after the community maintainers
have approved the changes.
Core committers also ensure that any issues with these
modules due to changes in the Ansible engine are
remediated.
Deploying By Ansible
o Community
Modules not supported by the core upstream developers,
partners, or companies, but maintained entirely by the
general open source community. Modules in this
category are still fully usable, but the response rate to
issues is purely up to the community. These modules are
# ansible-doc kubernetes
# ansible-doc k8s_raw
Custom Modules
Custom Modules are available on
https://github.com/ansible/ansible/issues
library = /usr/share/my_modules
Lab
1. Create a local user “student” on control node.
Summary
- Ansible Static Inventory