Using Ansible how to connect Oracle DB on Linux & run command "show pdb" to display oracle pluggable DB, "shutdown immediate" to stop DB and start DB

20 views
Skip to first unread message

Learner

unread,
Jul 22, 2023, 11:16:08 AM7/22/23
to Ansible Development
Hi All,

Code:   - name: Run show pdbs
    shell: |
      {{ oracle_home }}/bin/sqlplus / as sysdba <<EOF
      show pdbs;
      exit
      EOF
    register: query_output

  - name: Display query output
    debug:
      msg: "{{ query_output.stdout_lines }}"

Its getting failed with below error:

fatal: [10.192.90.43]: FAILED! => {"changed": true, "cmd": "\"{'stderr_lines': [], u'changed': True, u'end': u'2023-07-22 15:05:49.418929', 'failed': False, u'stdout': u'/u01/app/oracle/product/19.3.0.0/db_1', u'cmd': u\"cat /etc/oratab | egrep -v '^#|^$' | grep -v ASM | cut -d ':' -f2\", u'rc': 0, u'start': u'2023-07-22 15:05:49.413535', u'stderr': u'', u'delta': u'0:00:00.005394', 'stdout_lines': [u'/u01/app/oracle/product/19.3.0.0/db_1']}/bin/sqlplus / as sysdba <<EOF\nshow pdbs;\nexit\nEOF\"\n", "delta": "0:00:00.005358", "end": "2023-07-22 15:05:52.954037", "msg": "non-zero return code", "rc": 1, "start": "2023-07-22 15:05:52.948679", "stderr": "/bin/sh: {'stderr_lines': [], u'changed': True, u'end': u'2023-07-22 15:05:49.418929', 'failed': False, u'stdout': u'/u01/app/oracle/product/19.3.0.0/db_1', u'cmd': ucat: No such file or directory\ncut: fields are numbered from 1\nTry 'cut --help' for more information.", "stderr_lines": ["/bin/sh: {'stderr_lines': [], u'changed': True, u'end': u'2023-07-22 15:05:49.418929', 'failed': False, u'stdout': u'/u01/app/oracle/product/19.3.0.0/db_1', u'cmd': ucat: No such file or directory", "cut: fields are numbered from 1", "Try 'cut --help' for more information."], "stdout": "", "stdout_lines": []}

Learner

unread,
Jul 23, 2023, 1:07:14 PM7/23/23
to Ansible Development
Anyone please guide.

Brian Coca

unread,
Jul 24, 2023, 9:16:48 AM7/24/23
to Learner, Ansible Development
Several things seem to be off with your output, it looks like a
recursive copy into itself, aside from that, the base error does not
seem to match the commands shown:

'cmd': ucat: No such file or directory", "cut: fields are numbered
from 1", "Try 'cut --help' for more information.

Looks like typo in a shell command/script (meant `cat`?) or `ucat` is
not in the PATH


--
----------
Brian Coca

Learner

unread,
Jul 25, 2023, 2:55:07 AM7/25/23
to Ansible Development
Thank you for the response. what is the correct code I have to use?
Reply all
Reply to author
Forward
0 new messages