Ansible sqlplus

Can somebody explain me is there a possibility , without ssh to onto target VM
whether ansible can kickoff sqlplus or jndi connection to target db and run commands from ansible machine?

You could shell out locally and run this on the ansible host, if you provide all the remote database information to sqlplus. Of course you would need to have sqlplus installed locally with a working tnsnames.ora file configured. Another option if someone has time would be to develop an Ansible module that uses the cx_oracle python module.

H

February 6, 2017 4:52 PM, "Anand Dasari' via Ansible Development"
wrote:

Can somebody explain me is there a possibility , without ssh to onto target VM
whether ansible can kickoff sqlplus or jndi connection to target db and run
commands from ansible machine?

you're thinking much too complicated .. you can create a shell task and delegate
it to local ->

- name: execute statement
shell: |
{{ oracle_home }}/bin/sqlplus -S {{ connect }} << EOT
whenever sqlerror exit sql.sqlcode
set feedback off;
set pagesize 0;
set linesize 10000;
{{ sql }}
# TODO/FIXME: EOT is sent by magic?
register: sql_out
ignore_errors: true
delegate_to: 127.0.0.1

Another possibility would be to create an ansible python module which connects
through cx_Oracle ...

HTH

/jd

Hi,

I’ve written an oracle_sql module (which is in sort of an alpha stage) that connects via cx_Oracle and runs arbitrary sql or scripts.
It (and a bunch of others) can be found here.

regards
/M

It will be great if you could explain what goes in {{connect}}. I supplied the below to this variable but it did not work:

“@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host={{inventory_hostname}})(Port={{oraport}}))(CONNECT_DATA=(SERVICE_NAME={{orasvc}})))”

Ebby the connect variable would need to be the entire SQLPLUS connection string, user/pass included. I would suggest using the Oracle modules that have been created. They work really well cx_oracle and removes the need to inject data into sqlplus.