Saturday, 2 March 2019

Ansible Tower and Ansible project comparison

After being bought by Red Hat, Ansible continued to offer a free open source platform, which is currently called the Ansible Project. Red Hat has created proprietary management add-ons that offer an advanced control and centralization of the infrastructure, called Ansible Tower. Red Hat runs the Ansible Automation platform, which is composed of the Ansible Engine and Ansible Tower. This product is fully supported by Red Hat as one of its lead projects.



Ansible project

The Ansible project is a build-up of functionalities that come from the original company, AnsibleWorks. It is a community-built automation engine. It is free, open source, and available for anyone to download or install on any Linux OS, using the package manager, source compiling, or Python PyPI. It is very simple, powerful, and agentless.

To use the Ansible automation engine, users do not need any third-party applications or interfaces. They can simply send a command or write a playbook and execute it directly to the engine. This allows the user to access a variety of predefined modules, plugins, and APIs working as building blocks for managing all kinds of IT tasks and network objects. As it is agentless, Ansible relies on SSH to manage the Linux hosts, and WinRM for the Windows hosts. The SSH protocol is also used to control some of the network devices. Some more unsual devices or cloud and virtualization services require the use of Ansible pre-defined APIs to help manage or access them.


Nodes can be defined by their IP addresses or hostname; for the latter, we will have to rely on a DNS server or the local DNS file. APIs are used to communicate with third-party services, such as public or private clouds. Modules, which constitute Ansible's biggest pre-defined function library, allow the users to simplify long and complex tasks into a few lines in a playbook. They cover a large number of tasks, systems, packages, files, datastores, API calls, network device configurations, and so on. Finally, Ansible plugins are used to improve Ansible's core functionality, such as fast host caching, to avoid facts gathering on the network.


Ansible Tower

Ansible Tower is the Red Hat proprietary layer that sits on top of the Ansible project engine. It is made up of a number of add-ons and modules, composed of REST APIs and web services, that work together to create a friendly web interface that acts as an automation hub from which the IT administrator can select a number of tasks or playbooks to be executed on a number of machines. It still relies on the Ansible Engine to send commands and collect the reports. Ansible Tower cleverly collects the status of tasks and the reports that come back from hosts. All of this data is presented in the Ansible dashboard, showing hosts, the status of the inventory, and the recent jobs, activities, and snapshots.
Ansible Tower scales as the environment grows, and acts accordingly by showing in real-time all the statuses of the hosts, tasks, and playbooks. It highlights the successful playbook jobs, as well as those that failed to run, in order to troubleshoot any issues. In its multi-playbook workflows, the user can create pipelines of playbooks to be executed in sequence on any type of inventory, using one or more users' credentials and on a personalized timescale. With pipelining enabled, an IT administrator can automate complex operations (application provisioning, continuous deployment with containers, running test workflows) by breaking them down into smaller tasks using pipelines and, depending on the output (success or failure), run a specific play.


Ansible Tower offers a smart inventory platform that enables you to pull the host's inventory from any source, including a public or private cloud, or a local CMDB. The smart inventory builds hosts caching, which allows the user to run playbooks based on the facts of the hosts, which are pieces of information and properties related to them and gathered by Ansible. It also allows you to set up built-in notifications about the status of tasks, workflows, and playbooks via email, SMS, and push notifications on third-party platforms, such as Slack or Hipchat. Ansible Tower also allows task scheduling for routine updates, device patching, and custom backup schedule options. 

Ansible benefits and functionalities explained


With the rapid growth of IT infrastructures and a shift in the way applications are being deployed, IT administrators' tasks have grown in scale and complexity. Ansible seamlessly merges orchestration and configuration management in a very handy platform that allows IT administrators to define a selected number of nodes, applications, and network devices to be configured in a desired state by making clear which actions should be taken to remove repetition and reduce complexity.

Orchestration

As well as configuration management, Ansible also offers high-end orchestration. This makes the organization and management of the interactions between multiple configuration tasks well-structured. It simplifies and orders complex and chaotic configuration management and administration tasks. According to the status of the infrastructure, and the users' demands, applications, and data-versioned behaviors, Ansible orchestration will generally bring the infrastructure back to the desired state by configuring the appropriate services and policies via the CM tool into the failed component and make it work properly. 

IT orchestration can get very complex when dealing with DevOps class tasks, such as the continuous integration and deployment (CI/CD) of applications or infrastructure as a code (IaC). Ansible is capable of converting those tasks to automated workflows that run a number of playbooks in a well-defined structure, featuring all sorts of Ansible pre-defined modules, plugins, and APIs to communicate, execute commands, and report facts from any number of hosts, devices, and services.

Automate everything


Ansible is the path to take for better infrastructure automation, application deployment, and provisioning. It is the open source approach to an automated and modernized IT environment. Ansible is the key to enabling IT administrators to automate their daily tasks, freeing up their time to allow them to focus on delivering quality services. This not only impacts the IT department, but the business as a whole. The following diagram shows the reach of Ansible's multiple functionalities: 


Provisioning

Instance provisioning using Ansible covers the configuration and setup of bare-metal machines and servers. It relies on its predefined APIs to create and configure the local virtualized infrastructure. It can also manage hybrid, private, and public cloud instances, resources, and applications. Ansible can automatically install and configure an application and its libraries. It uses OS bootstrap and a kickstart script to initiate bare-metal machine provisioning using very simple playbooks and built-in modules. Using the same simple playbooks and different modules, Ansible can also provision instances, networking, and VMs in a public, private, or hybrid cloud very easily.

Configuration management

Using the power of playbooks and inventory, IT administrators can use Ansible to execute an update, patch, or configuration modification on a number of hosts, network devices, and applications. Playbooks describe the infrastructure in both simple, human-readable terms for other people to use, and machine-parsable code that can be used on any machine running Ansible. The execution of an Ansible configuration is state-driven, which means that it does not need to check the system or service state to know how to adapt in order to increase the task's reliability.

Application deployment

When we talk about applications that are managed by Ansible, we are talking about full life cycle control. Any users who have access to the Ansible server node, from IT administrators to application developers and project managers, will be able to manage all aspects of the application. Ansible takes the application package, deploys it to all the production servers, sets it up, and configures and initiates it. It can even test the package and report its status. This feature covers multi-tier applications, allowing zero-downtime rolling for a seamless application update.

Continuous delivery and continuous integration


Ansible ensures a stable environment for both developers and IT administrators for the continuous delivery and integration of applications. Automating as much as possible of the application turnaround means it is quick and unnoticeable to the application users. Ansible automation and orchestration is multi-tier and multi-step, which allows for finer control over operations and hosts. We can write Playbooks to manage the continuous integration and delivery of applications while ensuring the desired state of various components, such as load balancers and several server nodes.

Tuesday, 19 February 2019

Troubleshooting disk addition in multipath configuration in Linux


Introduction
Let me start by saying that the issue in this scenario was actually the result of a human error but I would still like to share the setup and steps I followed that finally helped me understand the problem and eventually resolve it.

The scenario
We received a new LUN of size 64GB from our storage team and it was to be scanned on the server, added to the multipath configuration and subsequently be used within LVM.

Step 1: Detect new disk
I executed the scsi-rescan -r and rescan-scsi-bus.sh commands so that the disk gets detected by the OS. I then used a script to get the disk device name to get the disk WWID mapping. The was basically a wrapper around the scsi_id command. For example:

[ssuri@example:~] $ sudo scsi_id -g -u -d /dev/sdamd
36005076801810718a800000000002a3b
[ssuri@example:~] $


Step 2: Add disk to udev and multipath
The disk was intended to be used for the /grid file system on a DB node. So I added the following lines in the /etc/udev/rules.d/99-dell-oracle-asm.rules file

KERNEL=="dm-*", PROGRAM="scsi_id --page=0x83 --whitelisted --device=/dev/%k", RESULT=="36005076801810718a800000000002c12", OWNER="root", GROUP="root"
ENV{DM_NAME}=="grid_pv1", OWNER="root", GROUP="root"

I wanted the disk alias name to be grid_pv1 and so I proceeded to add the corresponding entry in the /etc/multipath.conf file. I first added a line for the disk WWID in the blacklist_exceptions stanza.

wwid "36005076801810718a800000000002c12"

I then added the below stanza for the grid_pv1 disk in the multipaths stanza.

        multipath {
                uid 0
                gid 0
                wwid "36005076801810718a800000000002c12"
                alias grid_pv1
                mode 0600
        }

I then reloaded the required services with the following commands:

/sbin/service multipathd reload
/sbin/udevadm control --reload-rules
/sbin/udevadm trigger --type=subsystems --action=change
/sbin/udevadm trigger --type=devices --action=change


Step 3: Check that disk is visible in multipath configuration
After doing all the above, to my astonishment I could not see the disk in the multipath -ll output. I frantically rescanned the disk again, removed and added the udev and multipath configuration and reloaded the services numerous times. What finally caught my eye was when I saw that the disk was showing up as being blacklisted in the multipath -v3 command output.

 [ssuri@example:/var/ ] $ sudo multipath -v3 | grep -i 36005076801810718A800000000002c12
 Feb 16 05:56:30 | sdbgs: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgt: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgu: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgv: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgw: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgx: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgy: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted
 Feb 16 05:56:30 | sdbgz: uid = 36005076801810718a800000000002c12 (callout)
 Feb 16 05:56:30 | (null): (36005076801810718a800000000002c12) wwid blacklisted

In our multipath configuration we have a blanket wwid '*' as a blacklist rule. On seeing the above output I finally realized my mistake that the WWID entry I had added in udev and multipath configuration files actually had the alphabets 'a' and 'c' capitalized which was causing the disk WWID to still show up as blacklisted. 
On this realization I immediately corrected my mistake and restarted the services and rest assured the disk was now available in the multipath -ll output.

[ssuri@example:~] $ sudo multipath -ll grid_pv1
grid_pv1 (36005076801810718a800000000002c12) dm-384 IBM,2145
size=64G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 4:0:2:194 sdep  129:16   active ready running
  |- 6:0:0:194 sdaev 67:944   active ready running
  |- 5:0:0:194 sdpv  131:336  active ready running
  |- 7:0:3:194 sdazl 69:1328  active ready running
  |- 4:0:3:194 sdgl  132:16   active ready running
  |- 6:0:1:194 sdagr 70:944   active ready running
  |- 5:0:2:194 sdto  65:608   active ready running
  `- 7:0:7:194 sdbgz 65:1648  active ready running
[ssuri@example:~] $


Conclusion:
Although this issue was the result of a typing issue I do hope this helps you in diagnosing multipath related issues that you might be facing.

Tuesday, 22 January 2019

Setting up hyper V on Windows 10

I was using Oracle VirtualBox on my work laptop for almost two years until recently when I was asked to uninstall it owing to some licencing issues. Luckily my laptop came installed with Windows 10 which has hyper V installed by default. So, in this article I'll show you how to get hyper V up and running on Windows 10.

Prerequisite: Your system must have hardware virtualization turned on in the BIOS.

Step 1: 
In the search bar type "Turn Windows features on or off" and select it.



Step 2: 
Locate the hyper v checkbox and select it to enable hyper v.


This would require a system reboot.

Step 3: 
Now search for the hyper V manager in the search bar and select it to launch it.



You now have hyper V setup on you system and can start creating virtual machines.

Saturday, 24 November 2018

Configuring chrony time server in Centos 7

In this quick article we'll demonstrate how to configure the chrony time service in Linux. Configuring chrony is an exam objective for the RedHat as well as Linux Foundation exams.
Chrony is touted as an alternative for the popular ntpd daemon that has been used in UNIX/Linux systems for years now. Chrony has become more popular in desktop environments since time synchronization using chrony is very quick making it ideal for systems that get restarted frequently.

To install chrony, type the following command:

[root@cent7~]# yum install chrony
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                          | 7.7 kB  00:00:00
 * base: centos.mirror.myduniahost.com
 * epel: mirrors.aliyun.com
 * extras: mirror.0x.sg
 * updates: mirror.0x.sg
base                                                                                                                                          | 3.6 kB  00:00:00
epel                                                                                                                                          | 3.2 kB  00:00:00
extras                                                                                                                                        | 3.4 kB  00:00:00
updates                                                                                                                                       | 3.4 kB  00:00:00
(1/2): epel/x86_64/updateinfo                                                                                                                 | 932 kB  00:00:01
(2/2): epel/x86_64/primary                                                                                                                    | 3.6 MB  00:00:14
epel                                                                                                                                                     12716/12716
Package chrony-3.2-2.el7.x86_64 already installed and latest version
Nothing to do

Apparently it's already installed on my system.

Let's take a look at the available time servers in the chrony configuration file /etc/chrony.conf.

[root@cent7~]# grep -E '^server' /etc/chrony.conf
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
[root@cent7~]#

Now we'll enable and start the service.

[root@cent7 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@cent7 ~]# systemctl start chronyd

Let's check the status of the service now:

[root@cent7 ~]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-11-24 11:53:55 IST; 5s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 1796 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 1792 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1794 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─1794 /usr/sbin/chronyd

Nov 24 11:53:55 cent7 systemd[1]: Starting NTP client/server...
Nov 24 11:53:55 cent7 chronyd[1794]: chronyd version 3.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SECHASH +SIGND +ASYNCDNS +IPV6 +DEBUG)
Nov 24 11:53:55 cent7 systemd[1]: Started NTP client/server.

To obtain information about the time server we are currently syncing our time from, type the following command:

[root@cent7 ~]# chronyc tracking
Reference ID    : 768CB862 (sr-97-184-140-128-on-nets.com)
Stratum         : 3
Ref time (UTC)  : Sat Nov 24 06:24:05 2018
System time     : 0.000006578 seconds slow of NTP time
Last offset     : +0.007599837 seconds
RMS offset      : 0.007599837 seconds
Frequency       : 0.000 ppm slow
Residual freq   : +3831.410 ppm
Skew            : 1000000.000 ppm
Root delay      : 0.178650528 seconds
Root dispersion : 39.540195465 seconds
Update interval : 1.6 seconds
Leap status     : Normal

From the above output we can determine that we are currently syncing time from the server sr-97-184-140-128-on-nets.com.

To view the list of time servers available to us to sync from type the following command:

[root@cent7~]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- ntp.fra.de.as206479.net       2   6    37    53    +36ms[  +36ms] +/-  252ms
^* hkg1.m-d.net                  2   6    37    54  -1579us[  -17ms] +/-  117ms
^? 30-213-226-103-static.ch>     1   6     1    54  +1364us[  -14ms] +/-   93ms
^+ sr-97-184-140-128-on-net>     2   6    37    54  +1105us[+1105us] +/-  122ms

The * symbol indicates the time server we are currently syncing from.

I hope that you found this quick and easy setup of chrony to be useful.

Tuesday, 13 November 2018

host command as an alternative to nslookup

The nslookup command is the go to command for performing hostname/IP address lookups. It's a standard command found in Linux, UNIX and Windows distributions alike. While writing scripts we may come across requirements wherein we need the hostname and IP address information to be extracted from the output of the command.

If we use nslookup for this purpose then we would need to employ some interesting awk or grep commands to get the desired result. Given below is an example:

[root@lpic ~]# nslookup google.com
Server:         192.168.178.1
Address:        192.168.178.1#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.24.238

[root@lpic ~]# nslookup google.com | awk '/Address/ && !/#/ {print $2}'
172.217.160.206
[root@lpic ~]#

On the contrary now let's talk about the host command. host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. But I found it's output easier to read and extract desired fields from it. Here's an example:

[root@lpic ~]# host google.com
google.com has address 172.217.24.238
google.com has IPv6 address 2404:6800:4002:803::200e
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
[root@lpic ~]#
[root@lpic ~]# host google.com | awk '/has address/ {print $4}'
172.217.24.238
[root@lpic ~]#

I hope this quick tip has been helpful for you.

Tuesday, 3 April 2018

Using Perl DBI module to interact with an oracle database



In this article, I'll demonstrate how we can use the famous Perl DBI module to connect to an Oracle database. To connect to a database, DBI uses database driver modules (DBD) which handles the entire interaction between the queries typed within the Perl script and the actual database connectivity engine or in simple terms the database client. DBI comes available with the database driver for MySQL database by default as MySQL is the more popular database among folks engaged in web development.

The setup:
I'll be working with a Centos 6 system for the purpose of this demonstration and have installed the Oracle 11g database XE edition since it's quite easy to set up. I've also given the oracle user full superuser privileges temporarily.

So, let's get started.

Installing the DBD for Oracle:
Before downloading the package we need to make sure that we are logged in as the oracle user and the oracle user environment is set. To set the environment for Oracle XE edition, run the following script:

. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh 

This sets up environment variables like ORACLE_HOME etc.

Now let's download the DBD:Oracle package from CPAN via wget.

-bash-4.1$ wget http://search.cpan.org/CPAN/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.64.tar.gz
--2018-03-27 19:05:41--  http://search.cpan.org/CPAN/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.64.tar.gz
Resolving search.cpan.org... 199.15.176.188
Connecting to search.cpan.org|199.15.176.188|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.cpan.org/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.64.tar.gz [following]
--2018-03-27 19:05:46--  http://www.cpan.org/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.64.tar.gz
Resolving www.cpan.org... 151.101.2.49, 151.101.66.49, 151.101.130.49, ...
Connecting to www.cpan.org|151.101.2.49|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 444613 (434K) [application/x-gzip]
Saving to: “DBD-Oracle-1.64.tar.gz”

100%[=================================================================================================================================================>] 444,613      287K/s   in 1.5s

2018-03-27 19:05:50 (287 KB/s) - “DBD-Oracle-1.64.tar.gz” saved [444613/444613]


Now let's extract the package and take a look at what's inside.

-bash-4.1$ tar xzf DBD-Oracle-1.64.tar.gz
-bash-4.1$
-bash-4.1$ cd DBD-Oracle-1.64
-bash-4.1$ ls
Changes       dbdimp.c  dbivport.h  hints    lib      Makefile.PL  META.json  mkta.pl  oci.def     Oracle.h   README           README.mkdn  Todo
CONTRIBUTORS  dbdimp.h  examples    INSTALL  LICENSE  MANIFEST     META.yml   oci8.c   ocitrace.h  Oracle.xs  README.help.txt  t            typemap
-bash-4.1$

Before starting with the installation make sure that you have gcc installed as we'll need a C compiler to build the binaries from the source. Also, we need to export the following variables:

export ORACLE_USERID=hr/demo123
export ORACLE_DSN='dbi:Oracle:XE'

export LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib

The ORACLE_USERID is the user id and password for the user that we will use to connect to the database and ORACLE_DSN is the data source name which is the Oracle DBD name dbi:Oracle and the name of the database instance which is XE in this case. The LD_LIBRARY_PATH variable denotes the location where the installer should look for any library files it may require.


Now, execute the following commands to install the Oracle DBD package:

perl Makefile.PL

make

make test

sudo make install


Once the commands mentioned above complete successfully, check the installed versions of the DBI module and the database driver to ensure that the installation was successful.

-bash-4.1$ perl -e 'use DBI; print $DBI::VERSION,"\n";'
1.609
-bash-4.1$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";'
1.64
-bash-4.1


The working script:
Given below is a simple Perl script that uses the DBI module to connect to the XE instance and query some records from the table named employees. I executed the script successfully while logged in as the oracle user. I'm not certain if it'll work if executed as a different user.

#!/usr/bin/perl

use DBI;        #connect to database

$dbh=DBI->connect("dbi:Oracle:XE",'hr','demo123') or die "Error $! \n";

##connect function calls bliss function and creates the object $dbh#

$sth=$dbh->prepare("select EMPLOYEE_ID, FIRST_NAME from EMPLOYEES WHERE JOB_ID='SH_CLERK'") or die "Errors $! \n";

##prepare compiles the SQL query#

$res=$sth->execute();

eval {

$res=$sth->execute();
};

if($@) { print $@,"\n"; next; }
else { print "query executed successfully \n"; }

if($res) {

        print "EMPLOYEE_ID\tFIRST_NAME\n";
        while(@row=$sth->fetchrow_array) {
                print "$row[0]\t\t$row[1]\n";
                }

#$sth is also an object and fetchrow_array is a function that works on this object#
#fetchrow_array function fetches each record as a separate array element#
         }

$dbh->disconnect;


Conclusion:
In this article, we demonstrated how to install the database driver for Oracle and use it with the Perl DBI module to interact with an Oracle database.


Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...