Running Oracle SQL scripts with Ansible playbook

对着背影说爱祢 提交于 2019-12-07 06:49:39

问题


A look at the core database modules in Ansible documentation shows no signs of a module for Oracle. What is the best way to handle SQL/PLSQL deployments via Ansible for Oracle databases?

Are we expected to use roles from Ansible Galaxy to handle this? Very few people seem to have downloaded roles listed on Galaxy for Oracle.


回答1:


I have created a role to install apex 5 (where I first uninstall apex 4). I use modules like 'script' and 'shell'. I am not too happy about environment initialization but I am still learning. For any SQL/PLSQL task, sqlplus is the right tool. (perhaps SQLcl can do better..?)

- name: Determine apex version
  become: yes
  become_user: oracle
  shell: source /etc/profile &&  sqlplus -S / as sysdba @"{{ temp_dir }}/apexver.sql"
  register: apexver
  args:
     executable: /bin/bash
  changed_when: "'APEX_040000' in apexver.stdout"

- name: oracle apex remove
  become: yes
  become_user: oracle
  script: apex_remove.sh {{ item }} 
  with_items: 
    - 'XE'
  ignore_errors: yes
  register: result
  when: "'APEX_040000' in apexver.stdout"

22:18 $ cat apex_remove.sh
#!/bin/sh

# set oracle environment
. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
ORACLE_SID=$1

sqlplus -s /nolog <<EOF
connect / as sysdba
@?/apex/apxremov.sql
exit
EOF


来源:https://stackoverflow.com/questions/41341823/running-oracle-sql-scripts-with-ansible-playbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!