# Automate Oracle Database Shutdown and Startup with Ansible.

**URL:** <https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948>\
**Category:** Ansible Project\
**Created:** [May 16, 2020, 6:30am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948 "2020-05-16T06:30:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 6:30am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/1 "2020-05-16T06:30:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 16, 2020, 8:51am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/2 "2020-05-16T08:51:54Z")

</div>

Take a look at the xml module:  
[https://docs.ansible.com/ansible/latest/modules/xml\_module.html](https://docs.ansible.com/ansible/latest/modules/xml_module.html)  
More specifically the 3rd example, to retrieve information

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [May 16, 2020, 9:26am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/3 "2020-05-16T09:26:15Z")

</div>

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

Regards,

---

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 9:43am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/4 "2020-05-16T09:43:55Z")

</div>

Thanks Dick Visser, I am trying that module.

---

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 9:46am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/5 "2020-05-16T09:46:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 9:46am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/6 "2020-05-16T09:46:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 16, 2020, 9:47am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/7 "2020-05-16T09:47:06Z")

</div>

This should work:

&nbsp;&nbsp;&nbsp;&nbsp;- xml:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: inventory.xml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xpath: "/INVENTORY/HOME\_LIST/HOME[@NAME='OraDB12Home1']"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: attribute  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: out

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db12home: "{{ out.matches.0.HOME.LOC }}"

---

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 9:49am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/8 "2020-05-16T09:49:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Akshay\_Bora1](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Akshay\_Bora1](https://forum.ansible.com/u/Akshay_Bora1)\
**Post date:** [May 16, 2020, 9:50am UTC](https://forum.ansible.com/t/automate-oracle-database-shutdown-and-startup-with-ansible/32948/9 "2020-05-16T09:50:45Z")

</div>

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.
