klewan.ansible_role_oracle_manage_dbstate
Ansible Role: oracle-manage-dbstate
This role helps to manage the Oracle Database state, allowing you to start or shut it down.
Supported Operating Systems:
- RedHat
- CentOS
- OracleLinux
Requirements
This role depends on the oracle
role.
You need to define these variables:
oracle_manage_dbstate_oracle_home
→ This is the ORACLE_HOME path.oracle_manage_dbstate_oracle_sid
→ This is the ORACLE_SID.oracle_manage_dbstate_command
→ This is the command for starting up or shutting down.
Role Variables
Here are the available variables with their default values (see defaults/main.yml
):
oracle_manage_dbstate_oracle_home
:oracle_manage_dbstate_oracle_sid
:oracle_manage_dbstate_command
: # check 'oracle_manage_dbstate_commands'Acceptable commands for startup/shutdown:
- 'SHUTDOWN IMMEDIATE'
- 'STARTUP'
- 'STARTUP NOMOUNT'
- 'STARTUP MOUNT'
- 'STARTUP RESTRICT'
- 'STARTUP MOUNT RESTRICT'
- 'STARTUP UPGRADE'
Checks if the command for startup/shutdown is valid:
oracle_manage_dbstate_verify_command
: trueTo print the output of the sqlplus command:
oracle_manage_dbstate_print_command_output
: falseTo handle sqlplus errors (using 'whenever sqlerror exit 1'):
oracle_manage_dbstate_handle_sqlplus_errors
: trueCommand for handling sqlplus errors:
oracle_manage_dbstate_sqlplus_sqlerror_command
: "{% if oracle_manage_dbstate_handle_sqlplus_errors %}whenever sqlerror exit 1{% else %}{% endif %}"
Example Playbook
- name: Manage Oracle Database state (mount databases)
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
In vars/main.yml
or in group_vars/..
or host_vars/..
:
#-------------------------------------------------
# to override variables for the 'oracle-manage-dbstate' role
#-------------------------------------------------
# To print sqlplus command output:
oracle_manage_dbstate_print_command_output: true
# To handle sqlplus errors (using 'whenever sqlerror exit 1'):
oracle_manage_dbstate_handle_sqlplus_errors: false
License
GPLv3 - GNU General Public License v3.0
Author Information
This role was created in 2018 by Krzysztof Lewandowski.
Manage Oracle Database state (startup/shutdown)
ansible-galaxy install klewan.ansible_role_oracle_manage_dbstate