Skip to content

Ansible task to query and output Oracle DBID after creation #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
014445c
Ansible task to query and output Oracle DBID after creation
sahsagar-google Jul 7, 2025
4d80f21
Adding version dependent variables provisioning pre task
sahsagar-google Jul 9, 2025
616fe26
Adding a dbid logger role and using it in config db role to log DBID …
sahsagar-google Jul 10, 2025
9de8a18
Moving config variables to higher precedence group_vars and moving lo…
sahsagar-google Jul 12, 2025
ef17338
Adding a when condition as task is only relevant for GCE
sahsagar-google Jul 15, 2025
4f38e94
Moving the business logic to a new role and calling from config-db.yml
sahsagar-google Jul 16, 2025
2b08abc
Replacing underscore with hyphen in tag to be more consistent
sahsagar-google Jul 16, 2025
fd0a215
Adding oracle_home and oracle_sid as facts so the're available for re…
sahsagar-google Jul 16, 2025
2e0da06
Moving vars to group_vars so they are available for config-db.yml
sahsagar-google Jul 17, 2025
6c0455f
Removing unnecessary set facts variables
sahsagar-google Jul 17, 2025
c69da52
Removing unecessary environment definition from config db
sahsagar-google Jul 17, 2025
2e9bbf0
Undoing variable move changes since after removing env from config, t…
sahsagar-google Jul 17, 2025
2ee617c
Validating if presence of vars in group_vars succeeds the task
sahsagar-google Jul 18, 2025
b712ba4
Removing when conditions from config under the assumption that its RC…
sahsagar-google Jul 18, 2025
20e376e
Adding dbid logging call from RAC config as well
sahsagar-google Jul 18, 2025
0d3d8d7
fixing nit naming comments
sahsagar-google Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@
tasks_from: dg_mode
when: cluster_type == "DG"
tags: dg-create,dg-mode

- name: Get and Log Oracle DBID
hosts: dbasm
remote_user: "{{ oracle_user }}"
become: true
become_user: oracle
tasks:
- name: Include DBID logging role for current database instance
include_role:
name: dbid-logger
tags: log-dbid
11 changes: 11 additions & 0 deletions config-rac-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@
loop_var: role_item
when: create_db | bool
tags: rac-db-adjustments,rac-db-backups,rac-validation-scripts

- name: Get and Log Oracle DBID
hosts: dbasm
remote_user: "{{ oracle_user }}"
become: true
become_user: oracle
tasks:
- name: Include DBID logging role for current database instance
include_role:
name: dbid-logger
tags: log-dbid
17 changes: 17 additions & 0 deletions roles/dbid-logger/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
dependencies:
- role: common
38 changes: 38 additions & 0 deletions roles/dbid-logger/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- name: Execute SQL query to get DBID
ansible.builtin.shell: |
set -o pipefail
sqlplus -s / as sysdba <<EOF
SELECT dbid FROM v\$database;
EXIT;
EOF
environment:
ORACLE_HOME: "{{ oracle_home }}"
ORACLE_SID: "{{ oracle_sid }}"
PATH: "{{ oracle_home }}/bin:{{ ansible_env.PATH }}"
register: dbid_query_result
changed_when: false
failed_when: "'ORA-' in dbid_query_result.stderr"

- name: Extract DBID from query result
ansible.builtin.set_fact:
oracle_dbid: "{{ dbid_query_result.stdout_lines | select('match', '^\\d+$') | first | default('') | trim }}"

- name: Output DBID
ansible.builtin.debug:
msg: "ORACLE_DBID: {{ oracle_dbid }}"
when: oracle_dbid is defined and oracle_dbid | length > 0