使用 Ansible playbook 运行 Oracle SQL 脚本
查看 Ansible 中的核心数据库模块文档Oracle 模块.通过 Ansible for Oracle 数据库处理 SQL/PLSQL 部署的最佳方法是什么?
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?
我们是否希望使用来自 Ansible Galaxy 来处理这个问题?似乎很少有人下载 Galaxy for Oracle 上列出的角色.
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.
推荐答案
我创建了一个角色来安装 apex 5(我首先卸载了 apex 4).我使用像脚本"和外壳"这样的模块.我对环境初始化不太满意,但我仍在学习.对于任何 SQL/PLSQL 任务,sqlplus 都是正确的工具.(也许 SQLcl 可以做得更好..?)
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
相关文章