# oracle\_user module error expecting cx\_oracle in DB server

**URL:** <https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059>\
**Category:** Ansible Project\
**Created:** [January 25, 2020, 3:07pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059 "2020-01-25T15:07:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 25, 2020, 3:07pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/1 "2020-01-25T15:07:40Z")

</div>

I am trying to create oracle user using oracle\_user module in a RDS server. Here is my playbook

- hosts: all  
vars:  
oracle\_home: /home/ansible/instantclient\_12\_2  
user: SYSDBA  
password: \*\*\*\*\*\*  
prt: “1521”  
hostname: “RDS Instance”  
sname: TESTDB  
oracle\_env:  
ORACLE\_HOME: “{{oracle\_home}}”  
LD\_LIBRARY\_PATH: “{{oracle\_home}}”  
PATH: “{{oracle\_home}}”

vars\_files:

- vault-pass.yml

tasks:

- name: This playbook will create the user.  
oracle\_user:  
oracle\_home: /home/ansible/instantclient\_12\_2  
user: “{{user}}”  
password: “{{password}}”  
service\_name: “{{sname}}”  
port: “{{prt}}”  
hostname: “{{hostname}}”  
schema: \*\*\*\*\*  
schema\_password: \*\*\*\*  
default\_tablespace: USERS

# state: present

grants: “‘create session’, create any table’”  
environment: “{{oracle\_env}}”

This fails with below error  
FAILED! =\> {“changed”: false, “msg”: “The cx\_Oracle module is required. ‘pip install cx\_Oracle’ should do the trick. If cx\_Oracle is installed, make sure ORACLE\_HOME & LD\_LIBRARY\_PATH is set”}

DO we need to have cx\_oracle installed in the target server too? I had this same issue with oracle\_sql module too, but I used “connection: local” to enforced the playbook to look at the local cx\_oracle install. This is not working in oracle\_user module.

---

<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:** [January 25, 2020, 10:17pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/2 "2020-01-25T22:17:16Z")

</div>

Hi

Ansible doesn’t have such a module, so I assume this is a 3rd party module?  
In that case you might have more luck asking the module’s authors for support.

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 28, 2020, 5:05pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/3 "2020-01-28T17:05:16Z")

</div>

Hi,  
I am using oracle\_sql module and running a sql script. The sql script contains comments. The playbook fails because "  
FAILED! =\> {“changed”: false, “msg”: "Something went wrong while executing sql - ORA-00911: invalid character sql:

Is there a way I can keep the comments and execute the sql script ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 28, 2020, 5:18pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/4 "2020-01-28T17:18:00Z")

</div>

> Hi,  
> I am using oracle\_sql module and running a sql script. The sql script contains comments. The playbook fails because "  
> FAILED! =\> {"changed": false, "msg": "Something went wrong while executing sql - ORA-00911: invalid character sql:
> 
> Is there a way I can keep the comments and execute the sql script ?

I suppose you could filter out the comments. How does your SQL script looks like?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 28, 2020, 5:31pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/5 "2020-01-28T17:31:12Z")

</div>

My sql script will look like

/\* #######################################################################################################################################

# Program : xxxx.sql

# Programmer : xxxxx

# Date : xxxxx

# Usage : xxxx

# Revisions : xxxxx

# Dependencies :

# 1. Sqlplus Binaries.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 28, 2020, 5:33pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/6 "2020-01-28T17:33:25Z")

</div>

> My sql script will look like
> 
> /\*  
> #######################################################################################################################################  
> # Program : xxxx.sql  
> # Programmer : xxxxx  
> # Date : xxxxx  
> # Usage : xxxx  
> # Revisions : xxxxx  
> # Dependencies :  
> # 1. Sqlplus Binaries.  
> #  
> # Notes : Script will creates Oracle packages on AWS RDS.  
> # Author : xxxx  
> # Creates change passwords and lock a/c's  
> # after the user is done .
> 
> #######################################################################################################################################  
> \*/

So where is the SQL code?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 28, 2020, 6:05pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/7 "2020-01-28T18:05:38Z")

</div>

It goes soon after the comments

/\*

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 28, 2020, 8:37pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/8 "2020-01-28T20:37:26Z")

</div>

> It goes soon after the comments
> 
> /\*  
> #######################################################################################################################################  
> # Program : xxxx.sql  
> # Programmer : xxxxx  
> # Date : xxxxx  
> # Usage : xxxx  
> # Revisions : xxxxx  
> # Dependencies :  
> # 1. Sqlplus Binaries.  
> #  
> # Notes : Script will creates Oracle packages on AWS RDS.  
> # Author : xxxx  
> # Creates change passwords and lock a/c's  
> # after the user is done .  
> #######################################################################################################################################  
> \*/  
> set serveroutput on;  
> select username from dba\_users;  
> /  
> ..

Hello Anand,

given that this text is in the variable "sql", you can use the following filter:

{{sql | regex\_replace('/\\*([\\s\\S]\*)\\*/', '') | trim() }}

The result would be:

set serveroutput on;  
select username from dba\_users;

I found out that you have to use [\\s\\S]\* instead of the more straightforward .\* as .\* doesn't match newlines.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 30, 2020, 2:43pm UTC](https://forum.ansible.com/t/oracle-user-module-error-expecting-cx-oracle-in-db-server/32059/9 "2020-01-30T14:43:45Z")

</div>

Hi,  
Thank you so much. I made this work by commenting with – instead of #

Thank you for your help.
