Devops Ansible Helps for Oracle DBA’s

Oracle Database Automation using Ansible Tool 

  • Installation and Configuration of Ansible Here
  • Oracle Automation-Create a DBA User Using Ansible Tool Here
  • Oracle Automation-Creating Oracle 12c Database Using Ansible Tool Here
  • Oracle Automation-Applying PSU patch in Oracle 12c Database Using Ansible Tool Here

New generation of IT Automation  tools

  • Ansible
  • Salt
  • Puppet
  • Chef

About this Tools:

What can be Automated using Ansible Tool?

  • Server Setup
  • Code , App Install & Versioning
  • Database Creation
  • Database Software Install
  • Prerequisites
  • Webserver
  • Upgrades
  • Network
  • Patching
  • Maintenance
  • Backup & Recovery
  • Install PackagesCheck more on Ansible here

Introduction Of ANSIBLE:

Ansible is an agent-less IT automation tool developed in 2012 by Michael DeHaan, a former Red Hat associate.

The Ansible design goals are for it to be: minimal, consistent, secure, highly reliable, and easy to learn.

A Simple Automation Tool which uses YAML Syntax to perform Tasks Ansible is Written on Python Ansible is available as Open Source

ANSIBLE ARCHITECTURE:

Ansible Requirements & Install :

Control Machine

  • Ansible Software
  • Python

How to Install Ansible

  • Using Yum– Linux
  • Using apt– Ubuntu & Debain
  • Using brew– Mac Os
  • Pip– Python
  • Clone From Git

Note : Python is required in Target Machine for Certain Modules

Copy authorized_keys of the ansible control machine to target hosts

Ansible Version & Config :

  • After installing ansible you can check its version

ansible –version

  • Ansible will show the default Config file /etc/ansible/ansible.cfg
  • You can set parameters related to ansible

Ansible Inventory :

  • Inventory is set of hosts where automation will be executed
  • Inventory is mandatory for ansible
  • Inventory can be of two types
  1. Static
  2. Dynamic
  • Static Inventory is a file in INI format which contains the host names. Hostnames can be grouped based on the infrastructure of your company
  • By default /etc/ansible/hosts is the referenced inventory in ansible.cfg file. You can modify to different location
  • Ansible inventory file can also be specified at the run time using -i option of ansible command
  • Dynamic inventory is for getting information directly from CMDB or from any of the Cloud Provider like AWS,Azure,Digital ocean etc.

Ansible Playbooks :

  • Playbooks are the key components of ansible
  • Playbooks are set of instructions/tasks that are executed in the hosts through ansible automation.
  • Playbooks reside in ansible Control Server
  • Playbooks are written using YAML
  • Playbooks are Idempotent

Ansible Playbooks – YAML:

  • YAML – YAML Ain’t Markup Language
  • Human Readable Data Serialization Language
  • Similar to JSON
  • Human friendly
  • YAML uses Space indentations and no tabs
  • If Spacing is not properly specified syntax error is thrown

YAML Syntax

  • Start of the file —-
  • Comments #
  • Strings – Not required to be quoted
  • Boolean – True or False
  • Lists ( Sequences) – Like Arrays in JSON , Use hyphens
  • Dictionaries ( Mappings) – Like Objects in JSON

Ansible Playbook – Explanation :

  • hosts: This lists the host or host group against which we want to run the task
  • remote_user – tells Ansible to use a particular user.
  • Tasks – list of actions you want to perform
  • The name parameter represents what the task is doing
  • Modules – yum and service, have their own set of parameters

Example:

  • YUM – the state parameter has the latest value and it indicates that the httpd latest package should be installed. (yum install httpd)
  • SERVICE – the state parameter with the started value indicates that the httpd service should be started. (/etc/init.d/start)
  • “enabled” parameter defines whether the service should start at boot or not. ( service enable httpd)  
  • become: True tells that the tasks should be executed with sudo access. If sudoers does not contain that user it will throw an error. (sudo su -)

Ansible Playbook Execution :

Save the file in any text editor or IDE with extension *.yml or *.yaml

Command to Execute ansible playbook ansible-playbook –i all httpd_install.yml

If Groups are present then you can specify the group name ansible-playbook –i web httpd_install.yml

To check Syntax ansible-playbook –i web httpd_install.yml –check-syntax

Verbose

ansible-playbook –i web httpd_install.yml –v

ansible-playbook –i web httpd_install.yml –vv

ansible-playbook –i web httpd_install.yml –vvv

Ansible parses the playbook from top to bottom approach.

Below is the order followed in parsing a playbook

  • Variables are loaded
  • Facts are gathered
  • Pre_tasks are performed
  • Handlers
  • Role execution
  • Task execution
  • Handlers
  • Post_tasks

Execution strategies – Linear & Free

Ansible Variables:

Variables can be defined in the playbooks.

Variables can also be declared in a separate *.yml file and can be referenced in the playbook

Variables can also be passed during the command line using –e option

Use register to capture the output of any module into a variable

Variables can be defined at the host level or group level in the inventory file.

Summary :

  • Ansible is a simple IT automation tool
  • Inventory is the collection of hosts where the automation will be executed
  • Playbooks are the heart of Ansible and they are combination of multiple tasks
  • Tasks are the actions performed in remote hosts
  • Roles are collection of playbooks, files ,variables and templates to perform specific configuration tasks

References:-

https://www.doag.org/formes/pubfiles/7375105/2015-K-INF-Frits_Hoogland-Automating__DBA__tasks_with_Ansible-Praesentation.pdf

Catch Me On:- Hariprasath Rajaram

Telegram:https://t.me/joinchat/I_f4DkeGfZsxfzXxHD6gTg
LinkedIn:https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:https://www.facebook.com/HariPrasathdba
FB Group:https://www.facebook.com/groups/894402327369506/
FB Page: https://www.facebook.com/dbahariprasath/?
Twitter: https://twitter.com/hariprasathdba

What is Anisble?

Ansible is an open source automation platform. It is very, very simple to setup and yet powerful. Ansible can help you with configuration management, application deployment, task automation.

Ansible is an open-source IT automation engine which can remove drudgery from your work life, and will also dramatically improve the scalability, consistency, and reliability of your IT environment.

It can also do IT orchestration, where you have to run tasks in sequence and create a chain of events which must happen on several different servers or devices.

Example : If you have a group of web servers behind a load balancer. Ansible can upgrade the web servers one at a time and while upgrading it can remove the current web server from the load balancer and disable it in your Nagios monitoring system. So in short you can handle complex tasks with a tool which is easy to use.

What Ansible can automate?

Provisioning: Set up the various servers you need in your infrastructure.

Configuration management: Change the configuration of an application, OS, or device; start and stop services; install or update applications; implement a security policy; or perform a wide variety of other configuration tasks.

Application deployment: Make DevOps easier by automating the deployment of internally developed applications to your production systems.

Is Ansible Free?

YES!, Ansible is free to use and can be downloaded and installed from a number of sources, it will currently only run on a Linux or Mac that has Python installed. It will not run on Windows.

There are also some paid products i.e Ansible Engine a version of Ansible with full support from Red Hat and also Ansible Tower a GUI front end to drive Ansible core Ansible Tower is licensed on a per node basis.

But if you just want to download Ansible and use it for your home or production use – it is free to use.

The Keys Features of Ansible

Agentless

There is no software or agent to be installed on the client that communicates back to the server.

Idempotent

No matter how many times you call the operation, the result will be the same.

Simple and extensible

Ansible is written in Python and uses YAML for playbook language, both of which are considered relatively easy to learn.

What are Ansible roles?

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules. In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.
An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. … An Ansible playbook contains one or multiple plays, each of which define the work to be done for a configuration on a managed server. Ansible plays are written in YAML.
By default Ansible modules require python to be present in the target machines, since they are all written in python. … Another is speaking to any devices such as routers that do not have any Python installed. In any other case, using the shell or command module is much more appropriate.