Oracle Automation-Creating Oracle 12c Database Using Ansible Tool

Description:-

In this article we are going to see Oracle Automation-Oracle Database Creation Using Ansible Tool

Let’s start the Demo:-

Steps to create Oracle database using Ansible :-

Step 1:- Download the ansible modules from  github site.Click Here

Step 2:-Move the ZIP file to ansible server.

[root@ansible Desktop]# unzip ansible-oracle-master.zip
Archive: ansible-oracle-master.zip
1bbb35d690c102e23488537754ff8d1e0a99dc15
creating: ansible-oracle-master/
[root@ansible Desktop]# ls -lrt
total 4272
drwxrwxr-x. 8 ansible ansible 4096 Jun 26 2015 ansible-1.9.2
-rwxrw-rw-. 1 ansible ansible 75962 Jan 8 2018 ansible-oracle-modules-master.zip
-rwxrw-rw-. 1 ansible ansible 1642329 Jul 19 23:21 get-pip.py
-rwxrw-rw-. 1 ansible ansible 927525 Jul 25 02:59 ansible-1.9.2.tar.gz
-rwxrw-rw-. 1 ansible ansible 1357336 Jul 25 03:14 ansible-1.9.2-1.mga5.noarch.rpm
drwxr-xr-x. 7 root root 4096 Jul 30 11:12 ansible-oracle-master
drwxrwxr-x. 3 ansible ansible 4096 Jul 30 18:04 ansible-oracle-modules-master
-rwxrw-rw-. 1 ansible ansible 349507 Jul 30 22:33 ansible-oracle-master.zip

Step 3:- Create a single instance database on filesystem level

Sample file:- 

[root@ansible ]# cd ansible-oracle-master

[root@ansible ansible-oracle-master]# cat single-instance-db-on-fs.yml

[root@ansible ansible-oracle-master]#cat single-instance-db-on-fs.yml

- name: Host configuration
hosts: "{{ hostgroup }}"
become: yes
roles:
- common
- orahost
- cxoracle

- name: Database Server Installation & Database Creation
hosts: "{{ hostgroup }}"
become: yes
roles:
- oraswdb-install
- oradb-manage-db

- name: Database Server Installation & Database Creation
hosts: database-servers
user: oracle 
sudo: yes
roles:
- oraswdb-install
- oradb-create

Note :I have already installed all prerequisites and oracle binaries hence i am not using that role oraswdb-install

Step 4:- Go to  ansible-oracle-master/roles folder.Check oradb-create role is present for database creation.

[root@ansible ansible-oracle-master]# cd roles/
[root@ansible roles]# ls -lrt
total 0
drwxr-xr-x. 5 root root 61 Jul 30 11:12 oraswracdb-clone
drwxr-xr-x. 3 root root 21 Jul 30 11:12 orasw-meta
drwxr-xr-x. 5 root root 49 Jul 30 11:12 oraswgi-opatch
drwxr-xr-x. 6 root root 60 Jul 30 11:12 oraswgi-manage-patches
drwxr-xr-x. 5 root root 64 Jul 30 11:12 oraswgi-install
drwxr-xr-x. 6 root root 72 Jul 30 11:12 oraswgi-clone
drwxr-xr-x. 6 root root 60 Jul 30 11:12 oraswdb-manage-patches
drwxr-xr-x. 6 root root 60 Jul 30 11:12 oraswdb-install
drwxr-xr-x. 6 root root 61 Jul 30 11:12 orahost-storage
drwxr-xr-x. 4 root root 49 Jul 30 11:12 orahost-ssh
drwxr-xr-x. 5 root root 65 Jul 30 11:12 orahost-logrotate
drwxr-xr-x. 4 root root 49 Jul 30 11:12 orahost-cron
drwxr-xr-x. 7 root root 76 Jul 30 11:12 orahost
drwxr-xr-x. 5 root root 49 Jul 30 11:12 oraemagent-install
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-users
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-tablespace
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-services
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-roles
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-redo
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-pdb
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-parameters
drwxr-xr-x. 5 root root 44 Jul 30 11:12 oradb-manage-grants
drwxr-xr-x. 6 root root 76 Jul 30 11:12 oradb-manage-db
drwxr-xr-x. 5 root root 49 Jul 30 11:12 oradb-failover
drwxr-xr-x. 4 root root 33 Jul 30 11:12 oradb-delete
drwxr-xr-x. 5 root root 60 Jul 30 11:12 oradb-datapatch
drwxr-xr-x. 5 root root 49 Jul 30 11:12 oradb-create
drwxr-xr-x. 4 root root 49 Jul 30 11:12 oraasm-manage-diskgroups
drwxr-xr-x. 5 root root 49 Jul 30 11:12 oraasm-createdg
drwxr-xr-x. 4 root root 33 Jul 30 11:12 cxoracle
drwxr-xr-x. 5 root root 49 Jul 30 11:12 common

[root@ansible roles]# cd oradb-create
[root@ansible oradb-create]# ls -lrt
total 4
drwxr-xr-x. 2 root root 4096 Jul 30 11:12 templates
drwxr-xr-x. 2 root root 40 Jul 30 11:12 tasks
drwxr-xr-x. 2 root root 21 Jul 30 11:12 defaults
[root@ansible oradb-create]# ls -lrt templates/
total 332
-rwxr-xr-x. 1 root root 6119 Jul 30 11:12 netca.rsp.12.2.0.1.j2
-rw-r--r--. 1 root root 6131 Jul 30 11:12 netca.rsp.12.1.0.2.j2
-rw-r--r--. 1 root root 6131 Jul 30 11:12 netca.rsp.12.1.0.1.j2
-rwxr-xr-x. 1 root root 5954 Jul 30 11:12 netca.rsp.11.2.0.4.j2
-rwxr-xr-x. 1 root root 5954 Jul 30 11:12 netca.rsp.11.2.0.3.j2
-rw-r--r--. 1 root root 1283 Jul 30 11:12 dotprofile-db.j2
-rw-r--r--. 1 root root 29254 Jul 30 11:12 dbca-create-db.rsp.12.2.0.1.j2
-rwxr-xr-x. 1 root root 78121 Jul 30 11:12 dbca-create-db.rsp.12.1.0.2.j2
-rwxr-xr-x. 1 root root 78122 Jul 30 11:12 dbca-create-db.rsp.12.1.0.1.j2
-rwxr-xr-x. 1 root root 47467 Jul 30 11:12 dbca-create-db.rsp.11.2.0.4.j2
-rwxr-xr-x. 1 root root 47394 Jul 30 11:12 dbca-create-db.rsp.11.2.0.3.j2
[root@ansible oradb-create]# ls -lrt tasks/
total 8
-rwxr-xr-x. 1 root root 4014 Jul 30 11:12 main.yml
-rw-r--r--. 1 root root 706 Jul 30 11:12 listener.yml
[root@ansible oradb-create]# ls -lrt defaults
total 8
-rw-r--r--. 1 root root 6860 Jul 30 11:12 main.yml

Roles in ansible tool :-

Roles expect files to be in certain directory names. Roles must include at least one of these directories, however it is perfectly fine to exclude any which are not being used. When in use, each directory must contain a main.yml file, which contains the relevant content:

Role directory structure :-

roles/
   common/
     tasks/
     handlers/
     files/
     templates/
     vars/
     defaults/
     meta/
   webservers/
     tasks/
     defaults/
     meta/
  • tasks – contains the main list of tasks to be executed by the role.
  • defaults – default variables for the role 
  • templates- contains templates which can be deployed via this role.

Install tree rpm to see the execution of .yml file :-

[root@ansible roles]# yum install tree
Loaded plugins: langpacks, ulninfo
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 ol7_latest 46 k

Transaction Summary
==========================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 83 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm SUCCESS

Step 5:- Run the tree command and see the execution of .yml files to create a database

[root@ansible roles]# tree oraswdb-install
oraswdb-install
├── defaults
│   └── main.yml
├── meta
│   └── main.yml
├── tasks
│   ├── 11.2.0.3.yml
│   ├── 11.2.0.4.yml
│   ├── 12.1.0.1.yml
│   ├── 12.1.0.2.yml
│   ├── 12.2.0.1.yml
│   ├── 18.3.0.0.yml
│   ├── curl.yml
│   ├── get_url.yml
│   ├── init.yml
│   ├── install-home-db.yml
│   ├── main.yml
│   ├── remove-home.yml
│   └── systemd.yml
└── templates
├── db-install.rsp.11.2.0.3.j2
├── db-install.rsp.11.2.0.4.j2
├── db-install.rsp.12.1.0.1.j2
├── db-install.rsp.12.1.0.2.j2
├── db-install.rsp.12.2.0.1.j2
├── db-install.rsp.18.3.0.0.j2
├── dbora.j2
├── dotprofile-home.j2
├── glogin.sql.j2
├── oracle-rdbms-service.j2
├── oraInst.loc.j2
└── run-db-install.sh.j2

4 directories, 27 files

Step 6:- I have copied the single-instance-db-on-fs.yml file and named as dbcreation.yml as per the host entry and environment.

Change the main.yml entry present in defaults directory  as below:-

[root@ansible ~]# cd /home/ansible/Desktop/ansible-oracle-master/roles/oradb-create/defaults

The below data is used to create a new database using ansible tool.

[root@ansible ansible-oracle-master]# cat dbcreation.yml 

- name: Database Server Installation & Database Creation
hosts: db
user: oracle 
sudo: yes
roles:
- oradb-create

Step 7:- Run the playbook dbcreation.yml file to create a database.

[root@ansible ansible-oracle-master]# ansible-playbook dbcreation.yml

PLAY [Database Server Installation & Database Creation] *******************************************************

GATHERING FACTS ***************************************************************
ok: [test]

TASK: [oradb-create | set fact] ***********************************************
ok: [test] => (item={'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'})

TASK: [oradb-create | listener | Create responsefile for listener configuration] ***
ok: [test] => (item={'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'})

TASK: [oradb-create | listener | Create listener] **************************************************
ok: [test] => (item={'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'})

TASK: [oradb-create | Check if database is already created] *************************************************************
changed: [test] => (item={'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'})

TASK: [oradb-create | Copy custom dbca Templates to ORACLE_HOME/assistants/dbca/templates] ***
skipping: [test] => (item=[{'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'}])

TASK: [oradb-create | Create responsefile for dbca] ****************************************************
ok: [test] => (item=[{'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'}, {u'cmd': u'grep orcl:/u01/app/oracle/product/12.1.0/dbhome_1 /etc/oratab |wc -l', u'end': u'2018-07-30 17:41:58.213870', u'stderr': u'', u'stdout': u'0', u'changed': True, u'rc': 0, 'item': {'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'}, u'warnings': [], u'delta': u'0:00:00.060829', 'invocation': {'module_name': u'shell', 'module_args': u'grep orcl:/u01/app/oracle/product/12.1.0/dbhome_1 /etc/oratab |wc -l'}, 'stdout_lines': [u'0'], u'start': u'2018-07-30 17:41:58.153041'}])

TASK: [oradb-create | Create database(s)] ******************************************

changed: [test] => (item=[{'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'}, {u'cmd': u'grep orcl:/u01/app/oracle/product/12.1.0/dbhome_1 /etc/oratab |wc -l', u'end': u'2018-07-30 17:41:58.213870', u'stderr': u'', u'stdout': u'0', u'changed': True, u'rc': 0, 'item': {'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'}, u'warnings': [], u'delta': u'0:00:00.060829', 'invocation': {'module_name': u'shell', 'module_args': u'grep orcl:/u01/app/oracle/product/12.1.0/dbhome_1 /etc/oratab |wc -l'}, 'stdout_lines': [u'0'], u'start': u'2018-07-30 17:41:58.153041'}])

TASK: [oradb-create | debug var=item] **************************************
ok: [test] => (item=[u'Copying database files', u'1% complete', u'3% complete', u'11% complete', u'18% complete', u'26% complete', u'37% complete', u'Creating and starting Oracle instance', u'40% complete', u'45% complete', u'50% complete', u'55% complete', u'56% complete', u'60% complete', u'62% complete', u'Completing Database Creation', u'66% complete', u'70% complete', u'73% complete', u'85% complete', u'96% complete', u'100% complete', u'Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.']) => {
"item": [
"Copying database files",
"1% complete",
"3% complete",
"11% complete",
"18% complete",
"26% complete",
"37% complete",
"Creating and starting Oracle instance",
"40% complete",
"45% complete",
"50% complete",
"55% complete",
"56% complete",
"60% complete",
"62% complete",
"Completing Database Creation",
"66% complete",
"70% complete",
"73% complete",
"85% complete",
"96% complete",
"100% complete",
"Look at the log file \"/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log\" for further details."
],
"var": {
"item": [
"Copying database files",
"1% complete",
"3% complete",
"11% complete",
"18% complete",
"26% complete",
"37% complete",
"Creating and starting Oracle instance",
"40% complete",
"45% complete",
"50% complete",
"55% complete",
"56% complete",
"60% complete",
"62% complete",
"Completing Database Creation",
"66% complete",
"70% complete",
"73% complete",
"85% complete",
"96% complete",
"100% complete",
"Look at the log file \"/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log\" for further details."
]
}
}

TASK: [oradb-create | Add dotprofile (1)] *****************************************
ok: [test] => (item={'oracle_init_params': '', 'oracle_db_type': 'SI', 'service_name': 'orcl_serv', 'listener_name': 'LISTENER_ORCL', 'storage_type': 'FS', 'oracle_db_passwd': 'oracle', 'home': 'dbhome_1', 'is_container': False, 'redolog_size_in_mb': 100, 'num_pdbs': 1, 'pdb_prefix': 'pdb', 'oracle_db_name': 'orcl', 'state': 'present', 'oracle_edition': 'EE', 'oracle_db_mem_totalmb': 1024, 'oracle_database_type': 'MULTIPURPOSE', 'oracle_version_db': '12.1.0.2'})

test : ok=10 changed=2 unreachable=0 failed=0

Step 8:- Check the database and listener status in remote host test.localdomain.com

[oracle@test ~]$ ps -ef|grep pmon
oracle 1943 1875 0 19:19 pts/5 00:00:00 grep --color=auto pmon
oracle 22982 1 0 Jul29 ? 00:00:04 ora_pmon_test
oracle 64776 1 0 18:15 ? 00:00:00 ora_pmon_orcl

[oracle@test ~]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 30-JUL-2018 19:20:35
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test.localdomain.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 26-JUL-2018 15:59:24
Uptime 4 days 3 hr. 21 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/test/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test.localdomain.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=test.localdomain.com)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/test/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "test.localdomain.com" has 1 instance(s).
Instance "test", status READY, has 1 handler(s) for this service...
Service "testXDB.localdomain.com" has 1 instance(s).
Instance "test", status READY, has 1 handler(s) for this service...
The command completed successfully

 

Catch Me On:- Hariprasath Rajaram

Telegram:https://t.me/joinchat/I_f4DhGF_Zifr9YZvvMkRg
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

Installation and Configuration of Ansible

Installation and Configuration of Ansible

Introduction to 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 : minimal, consistent, secure, highly reliable, and easy to learn.Ansible is Written on Python language.It also available as Open Source.

Why to use Ansible as automation tool ?

  • There are many other IT automation tools available, including more mature ones like Puppet and Chef, so why would we choose Ansible? The main reason is simplicity.
  • Ansible is using YAML syntax. It’s simple configuration language.
    Puppet and Chef are using Ruby Syntax. which is more difficult to learn.
  • Ansible is an agentless tool.Instead of install an agent on every target machine, Ansible just requires that target systems have Python (on Linux servers) or PowerShell (on Windows servers) and SSH.But puppet and chef have to install agent on each target machines.

Architecture Diagram :-

High Level Steps :-

  • Install Python software
  • Install PIP to install Cx_Oracle package to perform SQL commands
  • Install ansible rpm
  • Configure SSH to connect remote hosts
  • Run the ansible command to access remote hosts.

Step 1:- Check the Current version of Python in OEL 7:-

[root@ansible ~]$ python -V
Python 2.7.5

Note:- Minimum version of python 2.7.6 is needed to install ansible.

Step 2:- Download the Python 2.7.6 package

[root@ansible ansible]# wget -c https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz --no-check-certificate
--2018-07-19 02:16:25-- https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
Resolving www.python.org (www.python.org)... 151.101.184.223, 2a04:4e42:2c::223
Connecting to www.python.org (www.python.org)|151.101.184.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14725931 (14M) [application/octet-stream]
Saving to: ‘Python-2.7.6.tgz’

100%[============================================================================================================>] 14,725,931 240KB/s in 65s

2018-07-19 02:17:32 (221 KB/s) - ‘Python-2.7.6.tgz’ saved [14725931/14725931]


Step 3:- Unzip the downloaded python package

[root@ansible ~]$ tar -xvzf Python-2.7.6.tgz 

[root@ansible ~]$ cd Python-2.7.6

[ansible@ansible Python-2.7.6]$ ls -lrt
total 956
-rw-r--r--. 1 ansible ansible 12749 Nov 10 2013 LICENSE
drwxr-xr-x. 2 ansible ansible 4096 Nov 10 2013 Include
drwxr-xr-x. 2 ansible ansible 20 Nov 10 2013 Grammar
drwxr-xr-x. 22 ansible ansible 4096 Nov 10 2013 Demo
drwxr-xr-x. 46 ansible ansible 8192 Nov 10 2013 Lib
drwxr-xr-x. 22 ansible ansible 4096 Nov 10 2013 Tools
-rw-r--r--. 1 ansible ansible 97308 Nov 10 2013 setup.py
drwxr-xr-x. 5 ansible ansible 4096 Nov 10 2013 RISCOS
-rw-r--r--. 1 ansible ansible 53972 Nov 10 2013 README
drwxr-xr-x. 2 ansible ansible 4096 Nov 10 2013 Python
-rw-r--r--. 1 ansible ansible 34829 Nov 10 2013 pyconfig.h.in
drwxr-xr-x. 2 ansible ansible 4096 Nov 10 2013 PCbuild
drwxr-xr-x. 10 ansible ansible 4096 Nov 10 2013 PC
drwxr-xr-x. 2 ansible ansible 4096 Nov 10 2013 Parser
drwxr-xr-x. 3 ansible ansible 4096 Nov 10 2013 Objects
drwxr-xr-x. 9 ansible ansible 4096 Nov 10 2013 Modules
drwxr-xr-x. 5 ansible ansible 4096 Nov 10 2013 Misc
-rw-r--r--. 1 ansible ansible 44172 Nov 10 2013 Makefile.pre.in
drwxr-xr-x. 11 ansible ansible 4096 Nov 10 2013 Mac
-rwxr-xr-x. 1 ansible ansible 7122 Nov 10 2013 install-sh
-rw-r--r--. 1 ansible ansible 133573 Nov 10 2013 configure.ac
-rwxr-xr-x. 1 ansible ansible 426595 Nov 10 2013 configure
-rwxr-xr-x. 1 ansible ansible 35639 Nov 10 2013 config.sub
-rwxr-xr-x. 1 ansible ansible 44851 Nov 10 2013 config.guess
drwxr-xr-x. 16 ansible ansible 4096 Nov 10 2013 Doc

Step 4:- Configuring python 2.7.6 software

Create the below directory ‘/home/ansible/python’ and configure,install the software.

[ansible@ansible Python-2.7.6]# ./configure --prefix=/home/ansible/python

[ansible@ansible Python-2.7.6]# make

[ansible@ansible Python-2.7.6]# make install

After installation,the following files are created under ‘/home/ansible/python’

[ansible@ansible Python-2.7.6]# ls -lrt /home/ansible/python
total 4
drwxr-xr-x. 3 ansible ansible 22 Jul 19 21:10 include
drwxr-xr-x. 4 ansible ansible 59 Jul 19 21:10 lib
drwxr-xr-x. 3 ansible ansible 16 Jul 19 21:10 share
drwxr-xr-x. 2 ansible ansible 4096 Jul 19 21:10 bin

Now,check the new python version 2.7.6

[root@ansible ~]$ cd python/bin/
[root@ansible bin]$ python -V
Python 2.7.6

[root@ansible bin]# which python
/home/ansible/bin/python

Step 5:- Download PIP package

[root@ansible ~]$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1603k 100 1603k 0 0 164k 0 0:00:09 0:00:09 --:--:-- 222k

[root@ansible ansible]# python get-pip.py
Collecting pip
Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 709kB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
100% |████████████████████████████████| 51kB 1.2MB/s
Installing collected packages: pip, wheel
Successfully installed pip-10.0.1 wheel-0.31.1

[root@ansible ansible]# python -m pip install cx_Oracle --upgrade
Collecting cx_Oracle
Downloading https://files.pythonhosted.org/packages/3b/09/6b10675a6db7c7da1b8d23225f0a95b2a45248c56a1e8f711d59809278d3/cx_Oracle-6.4.1-cp27-cp27mu-manylinux1_x86_64.whl (590kB)
100% |████████████████████████████████| 593kB 1.2MB/s
Installing collected packages: cx-Oracle
Successfully installed cx-Oracle-6.4.1

Check the PIP version :-

[root@ansible ansible]# pip -V
pip 10.0.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

We need the Cx_Oracle Package for executing SQL’s , performing any task inside SQL prompt.

[root@ansible ansible]# python
Python 2.7.5 (default, Sep 5 2016, 02:30:38)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> exit()

Installation of Ansible software :-

Step 6:-To get Ansible for Linux, first ensure that the RHEL7 EPEL repository is installed:

[root@ansible ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
warning: /var/tmp/rpm-tmp.dwLJVq: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:epel-release-7-11 ################################# [100%]

Step 7:- Once the repository is installed, install Ansible with yum:

[root@ansible ~]# yum install ansible

Step 8:- Check the ansible version and configuration file path

[root@ansible ~]$ ansible --version
ansible 2.6.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, Sep 5 2016, 02:30:38) [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)]

Step 9:- Configuring ansible hosts and create inventory file.

The ‘databaseservers‘ in the brackets indicates as group names to list number of remote hosts.

[root@ansible ~]# vi /etc/ansible/hosts

Added the below remote host entry to the /etc/ansible/hosts file

[database-servers]
demo.localdomain.com

Step 10:- List the remote hosts which are able to use ansible commands

[root@ansible ~]$ ansible --list-host all
hosts (1):
192.168.86.141

[ansible@ansible ~]$ ansible --list-host database-servers
hosts (1):
192.168.86.141

SSH Key creation :-

Step 11:- Create the SSH user equivalence in the ansible server.

[ansible@ansible ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
3f:58:1b:ca:6c:2a:66:0d:63:ea:c3:18:a3:45:45:43 ansible@ansible.localdomain.com
The key's randomart image is:
+--[ RSA 2048]----+
| oE |
| .. |
| . |
| . |
| . S o |
|o . + o = o |
|.* o + * + |
|o + + .o . |
| ..+ .. |
+-----------------+

[ansible@ansible ~]$ cd .ssh/
[ansible@ansible .ssh]$ ls -lrt
total 8
-rw-r--r--. 1 ansible ansible 413 Jul 20 19:40 id_rsa.pub
-rw-------. 1 ansible ansible 1675 Jul 20 19:40 id_rsa

Step 12:- Copy the SSH key to the remote servers

[root@ansible .ssh]# ssh-copy-id root@demo.localdomain.com
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@demo.localdomain.com's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@demo.localdomain.com'"
and check to make sure that only the key(s) you wanted were added.

Step 13:- Now,we are able to ping the remote hosts,

[root@ansible .ssh]# ansible all -m ping
demo.localdomain.com | SUCCESS => {
"changed": false,
"ping": "pong"

Step 14 :- To check the partitions on all remote hosts

[root@ansible ~]# ansible -m command -a "df -h" database-servers
demo.localdomain.com | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rac1-lv_root
36G 19G 16G 55% /
tmpfs 2.0G 276K 2.0G 1% /dev/shm
/dev/sda1 485M 82M 378M 18% /boot

Catch Me On:- Hariprasath Rajaram

Telegram:https://t.me/joinchat/I_f4DhGF_Zifr9YZvvMkRg
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