klewan.ansible_role_oracle_manage_dbstate
Ansible 角色:oracle-manage-dbstate
管理 Oracle 数据库状态(启动/关闭)。
支持的操作系统:
- RedHat
- CentOS
- OracleLinux
要求
此角色使用 oracle
角色。
需要定义以下变量:
oracle_manage_dbstate_oracle_home
-> ORACLE_HOMEoracle_manage_dbstate_oracle_sid
-> ORACLE_SIDoracle_manage_dbstate_command
-> 启动/关闭命令及其选项
角色变量
可用变量如下,包含默认值(请参见 defaults/main.yml
):
# ORACLE_HOME
oracle_manage_dbstate_oracle_home:
# ORACLE_SID
oracle_manage_dbstate_oracle_sid:
# 要执行的启动/关闭命令
oracle_manage_dbstate_command: # 请查看 'oracle_manage_dbstate_commands'
# 可接受的启动/关闭命令
oracle_manage_dbstate_commands:
- 'SHUTDOWN IMMEDIATE'
- 'STARTUP'
- 'STARTUP NOMOUNT'
- 'STARTUP MOUNT'
- 'STARTUP RESTRICT'
- 'STARTUP MOUNT RESTRICT'
- 'STARTUP UPGRADE'
# 验证启动/关闭命令是否有效
oracle_manage_dbstate_verify_command: true
# 打印 sqlplus 命令输出
oracle_manage_dbstate_print_command_output: false
# 处理 sqlplus 错误,即执行 'whenever sqlerror exit 1'
oracle_manage_dbstate_handle_sqlplus_errors: true
# sqlplus 错误处理命令
oracle_manage_dbstate_sqlplus_sqlerror_command: "{% if oracle_manage_dbstate_handle_sqlplus_errors %}whenever sqlerror exit 1{% else %}{% endif %}"
示例剧本
- name: 管理 Oracle 数据库状态(挂载数据库)
hosts: ora-servers
gather_facts: true
become: true
become_user: '{{ oracle_user }}'
tasks:
- import_role:
name: oracle-gatherinfo-gi
tags:
- oracle-gatherinfo-gi
- import_role:
name: oracle-gatherinfo-databases
tags:
- oracle-gatherinfo-databases
- include_role:
name: oracle-manage-dbstate
vars:
oracle_manage_dbstate_oracle_home: '{{ _oracle_homes_backup_outer_item.oracle_home }}'
oracle_manage_dbstate_oracle_sid: '{{ _oracle_homes_backup_outer_item.instance_name }}'
oracle_manage_dbstate_command: "STARTUP MOUNT"
oracle_manage_dbstate_handle_sqlplus_errors: true
with_items:
- "{{ oracle_databases }}"
loop_control:
label: "[ORACLE_HOME: {{ _oracle_homes_backup_outer_item.oracle_home }}]"
loop_var: _oracle_homes_backup_outer_item
when: _oracle_homes_backup_outer_item.instance_name == 'ORCL'
tags:
- oracle-manage-dbstate
在 vars/main.yml
或 group_vars/..
或 host_vars/..
中:
#-------------------------------------------------
# 重写角色 'oracle-manage-dbstate' 变量
#-------------------------------------------------
# 打印 sqlplus 命令输出
oracle_manage_dbstate_print_command_output: true
# 处理 sqlplus 错误,即执行 'whenever sqlerror exit 1'
oracle_manage_dbstate_handle_sqlplus_errors: false
许可
GPLv3 - GNU 通用公共许可证 v3.0
作者信息
该角色由 Krzysztof Lewandowski 于 2018 年创建。