DevOps - Unit - 5
DevOps - Unit - 5
Configuration Management
• ANSIBLE: Introduction to Ansible
• Ansible tasks
• Roles
• Jinja2 templating
• Vaults
• Deployments using Ansible
• Containerization using Kubernetes
• Introduction to Kubernetes
• Namespace & Resources
• CI/CD – on GCP
• Deploying Apps on Openshift Container Pods
What is Configuration Management?
Introduction to Ansible
• Ansible is an IT automation tool.
• It can configure systems, deploy software, and orchestrate more
advanced IT tasks such as continuous deployments or zero
downtime rolling updates.
• Ansible is easy to deploy because it does not use any agents or
custom security infrastructure.
• Ansible uses playbook to describe automation jobs, and playbook
uses very simple language i.e. YAML (Yet Another Mark-up
Language)
How Ansible Works?
• 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.
• The management node in the picture is the controlling node
(managing node) which controls the entire execution of the
playbook.
• It’s the node from which you are running the installation.
• The inventory file provides the list of hosts where the Ansible
modules needs to be run and the management node does a SSH
connection and executes the small modules on the hosts machine
and installs the product/software.
• Beauty of Ansible is that it removes the modules once those are
installed so effectively it connects to host machine , executes the
instructions.
• If it’s successfully installed removes the code which was copied on
the host machine which was executed.
Ansible Tasks
Directory Structure:
tasks - contains the main list of tasks to be executed by the role.
handlers - contains handlers, which may be used by this role or even anywhere outside this
role.
defaults - default variables for the role.
vars - other variables for the role. Vars has the higher priority than defaults.
files - contains files required to transfer or deployed to the target machines via this role.
templates - contains templates which can be deployed via this role.
meta - defines some data / information about this role (author, dependency, versions,
examples, etc,.)
https://www.devopsschool.com/tutorial/ansible/ansible-roles-explained-with-examples.html
Jinja2 template
• Jinja2 is a powerful and easy to use python-based templating engine
that comes in handy in an IT environment with multiple servers
where configurations vary every other time.
• Creating static configuration files for each of these nodes is tedious
and may not be a viable option since it will consume more time and
energy.
• And this is where templating comes in.
• Jinja2 templates are simple template files that store variables that
can change from time to time.
• When Playbooks are executed, these variables get replaced by
actual values defined in Ansible Playbooks.
• This way, templating offers an efficient and flexible solution to
create or alter configuration file with ease.
Template architecture
• A Jinja2 template file is a text file that contains variables that get
evaluated and replaced by actual values upon runtime or code
execution.
• In a Jinja2 template file, you will find the following tags:
• In most cases, Jinja2 template files are used for creating files or
replacing configuration files on servers.
• Template files bear the .j2 extension, implying that Jinja2
templating is in use.
• Creating template files
• Here’s an example of a Jinja2 template file example_template.j2
which we shall use to create a new file with the variables shown.
• Pods
• Deployments
• Services
• ConfigMap
• Secrets
• Persistant Volumes
• Stateful sets
• Daemon Sets
• Jobs and Cronjobs
• Pods: Pods are the smallest deployable units of computing that you
can create and manage in Kubernetes.