Hi Team,
Please find the expected result from the database.
SQL> SELECT DESTINATION FROM V$ARCHIVE_DEST
WHERE STATUS != ‘INACTIVE’; 2
DESTINATION
/arch/DVC4I/CDSD0490
I want to store “/arch/DVC4I/CDSD0490” into a variable.
I wrote the following code
-
name: Run query as Oracle user using sudo su
hosts: oracle_hosts
become: yes
become_user: orac4itasks:
- name: Run SQL query via sudo su
shell: |
sudo su - orac4i -c “sqlplus / as sysdba <<EOF
SELECT DESTINATION FROM V\$ARCHIVE_DEST WHERE STATUS != ‘INACTIVE’;
exit;
EOF”
register: archive_destination
become: yes - name: Display Results
debug:
msg: “Oracle Archive Destination: {{ archive_destination }}”
- name: Run SQL query via sudo su
But the archive_destination stores more information than expected.
TASK [Display Results] ********************************************************************************************************************************************************************************
ok: [caddld-590.belldev.dev.bce.ca] => {
“msg”: “Oracle Archive Destination: {‘stderr_lines’: , u’changed’: True, u’end’: u’2025-03-19 16:37:42.763075’, ‘failed’: False, u’stdout’: u’\nSQLPlus: Release 19.0.0.0.0 - Production on Wed Mar 19 16:37:42 2025\nVersion 19.24.0.0.0\n\nCopyright (c) 1982, 2024, Oracle. All rights reserved.\n\n\nConnected to:\nOracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production\nVersion 19.24.0.0.0\n\nSQL> \nDESTINATION\n--------------------------------------------------------------------------------\n/arch/DVC4I/CDSD0490\n\nSQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production\nVersion 19.24.0.0.0’, u’cmd’: u’sudo su - orac4i -c "sqlplus / as sysdba <<EOF\nSELECT DESTINATION FROM V\\\\\\$ARCHIVE_DEST WHERE STATUS != \‘INACTIVE\’; \nexit;\nEOF"\n’, u’rc’: 0, u’start’: u’2025-03-19 16:37:42.343045’, u’stderr’: u’‘, u’delta’: u’0:00:00.420030’, ‘stdout_lines’: [u’', u’SQLPlus: Release 19.0.0.0.0 - Production on Wed Mar 19 16:37:42 2025’, u’Version 19.24.0.0.0’, u’‘, u’Copyright (c) 1982, 2024, Oracle. All rights reserved.’, u’‘, u’‘, u’Connected to:’, u’Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production’, u’Version 19.24.0.0.0’, u’‘, u’SQL> ‘, u’DESTINATION’, u’--------------------------------------------------------------------------------‘, u’/arch/DVC4I/CDSD0490’, u’‘, u’SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production’, u’Version 19.24.0.0.0’], u’warnings’: [u"Consider using ‘become’, ‘become_method’, and ‘become_user’ rather than running sudo"]}”
}
Kindly advise.
Is there any other method to connect oracle database sqlplus “/as sysdba” with shell module?
Regards
Guru