我正在尝试运行 playbook 来执行 Oracle 脚本。
---
- hosts: localhost
- tasks:
- set_fact:
execute_command: "sqlplus {{ Oracle_Username }}/{{ Oracle_Password }} @{{ sqlfile.sql }}"
- name: Get Object_details
shell: "echo exit | {{ execute_command }} >> ./Oracle_Output.csv"
environment:
ORACLE_HOME: "{{ Oracle_DBServer }}"
ORACLE_SID: "{{ Oracle_SID }}"
我已经在 vars 中声明了所有变量。当我执行它时,收到错误“set_fact 不是播放的有效属性”。 使用 Ansible 运行 SQL 脚本的最佳方式是什么?我必须在变量中声明所有连接详细信息。
最佳答案
---
- hosts: localhost
- tasks:
- name: Get Object_details
shell: echo exit |sqlplus "{{ oracle_username }}/ {{ oracle_pwd}} @(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host={{ oracle_hostname }} )(Port={{ oracle_port }}))(CONNECT_DATA=(SERVICE_NAME= {{ service_name }})))"@sqlfile.sql;
通过上面的代码,我们将能够直接连接到Oracle主机并执行sql脚本。如果默认情况下未定义 Oracle 环境变量,我们也可以在 playbook 任务本身中进行设置。下面是一个例子:
---
- hosts: localhost
- tasks:
- name: Get Object_details
shell: echo exit |sqlplus "{{ oracle_username }}/ {{ oracle_pwd}} @(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host={{ oracle_hostname }} )(Port={{ oracle_port }}))(CONNECT_DATA=(SERVICE_NAME= {{ service_name }})))"@sqlfile.sql;
environment:
ORACLE_HOME: <<Oracle Home path >>
PATH: << bin path >>
LD_LIBRARY_PATH: << lib path >>
关于oracle - Ansible playbook 执行 Oracle 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41796466/