Automate Oracle Database Shutdown and Startup with Ansible.

61 views
Skip to first unread message

Akshay Bora

unread,
May 16, 2020, 2:30:07 AM5/16/20
to Ansible Project
Hi Everyone,

I am writing an ansible script to automate the task of oracle database shutdown and startup. I am facing a difficulty in reading the environment variables from the XML files. 

Sample XML File:

[oracle@rac1 ContentsXML]$ more inventory.xml
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2014, Oracle and/or its affiliates.
All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>12.1.0.2.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="OraGI12Home1" LOC="/grid/app/product/12.1.0" TYPE="O" IDX="1" CRS="true"/>
<HOME NAME="OraDB12Home1" LOC="/oracle/app/product/12.1.0" TYPE="O" IDX="2"/>
</HOME_LIST>
<COMPOSITEHOME_LIST>
</COMPOSITEHOME_LIST>
</INVENTORY>
[oracle@rac1 ContentsXML]$

One challenge for this is the path of this XML file is not same on every server.

Can someone please help me to fetch the exact path of the xml file and grep the value of OraDB12Home1= /oracle/app/product/12.1.0 out of xml and store in ansible variable? 

Dick Visser

unread,
May 16, 2020, 4:52:26 AM5/16/20
to ansible...@googlegroups.com
Take a look at the xml module:
https://docs.ansible.com/ansible/latest/modules/xml_module.html
More specifically the 3rd example, to retrieve information
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d78cb9de-e120-4f5e-9414-8576f9c84632%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Jean-Yves LENHOF

unread,
May 16, 2020, 5:27:04 AM5/16/20
to ansible...@googlegroups.com

There's no /etc/oratab on yours servers ?

Regards,

Akshay Bora

unread,
May 16, 2020, 5:43:55 AM5/16/20
to Ansible Project
Thanks Dick Visser, I am trying that module.

Akshay Bora

unread,
May 16, 2020, 5:46:13 AM5/16/20
to Ansible Project
Jean, there is /etc/oratab file, but I am not able to read exact value from that file. As if there are multiple databases are running with different homes, its bit difficult to read /etc/oratab. But if you are aware of reading values from it and saving in variable, please help me with it.


On Saturday, May 16, 2020 at 12:00:07 PM UTC+5:30, Akshay Bora wrote:

Akshay Bora

unread,
May 16, 2020, 5:46:55 AM5/16/20
to Ansible Project
Jean, there is /etc/oratab file, but I am not able to read exact value from that file. As if there are multiple databases are running with different homes, its bit difficult to read /etc/oratab. But if you are aware of reading values from it and saving in variable, please help me with it.

To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

Dick Visser

unread,
May 16, 2020, 5:47:31 AM5/16/20
to ansible...@googlegroups.com
This should work:

- xml:
path: inventory.xml
xpath: "/INVENTORY/HOME_LIST/HOME[@NAME='OraDB12Home1']"
content: attribute
register: out

- set_fact:
db12home: "{{ out.matches.0.HOME.LOC }}"
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1215d595-71e2-4a77-a15e-5f6b7552c030%40googlegroups.com.

Akshay Bora

unread,
May 16, 2020, 5:50:07 AM5/16/20
to ansible...@googlegroups.com
Thanks Dick, I will try this and let you know , as of now I am getting an error of installing lxml module, will fix it first and try.
Thanks a ton.

Akshay Bora

unread,
May 16, 2020, 5:50:45 AM5/16/20
to Ansible Project
Thanks Dick, I will try this and let you know , as of now I am getting an error of installing lxml module, will fix it first and try.
Thanks a ton.

> To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages