Automate Oracle Database Shutdown and Startup with Ansible.

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" ?> 12.1.0.2.0 2.1.0.6.0 [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?

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

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

Regards,

Thanks Dick Visser, I am trying that module.

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.

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.

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 }}"

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.

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.