Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update oracle_sql #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions oracle_sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ options:
required: false
default: None
aliases: ['pw']
net_service_name:
description:
- The NetServiceName to connect to the database (use the tnsname.ora)
required: false
default: None
aliases: ['pw']
service_name:
description:
- The service_name to connect to the database
Expand Down Expand Up @@ -142,6 +148,7 @@ def main():
user=dict(required=False, aliases=['un', 'username']),
password=dict(required=False, no_log=True, aliases=['pw']),
mode=dict(default="normal", choices=["sysasm", "sysdba", "normal"]),
nsn=dict(required=False, aliases=['nsn']),
service_name=dict(required=False, aliases=['sn']),
hostname=dict(required=False, default='localhost', aliases=['host']),
port=dict(required=False, default=1521),
Expand All @@ -155,6 +162,7 @@ def main():
user = module.params["user"]
password = module.params["password"]
mode = module.params["mode"]
nsn = module.params["nsn"]
service_name = module.params["service_name"]
hostname = module.params["hostname"]
port = module.params["port"]
Expand All @@ -181,17 +189,27 @@ def main():

elif user and password:
if mode == 'sysdba':
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn, mode=cx_Oracle.SYSDBA)
if not nsn :
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn, mode=cx_Oracle.SYSDBA)
else:
conn = cx_Oracle.connect(user, password, nsn, mode=cx_Oracle.SYSDBA)

elif mode == 'sysasm':
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn, mode=cx_Oracle.SYSASM)
if not nsn :
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn, mode=cx_Oracle.SYSASM)
else:
conn = cx_Oracle.connect(user, password, nsn, mode=cx_Oracle.SYSASM)
else:
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn)
if not nsn :
dsn = cx_Oracle.makedsn(host=hostname, port=port, service_name=service_name)
connect = dsn
conn = cx_Oracle.connect(user, password, dsn)
else:
conn = cx_Oracle.connect(user, password, nsn)

elif not user or not password:
module.fail_json(msg='Missing username or password for cx_Oracle')
Expand Down