Skip to content

Commit

Permalink
Update oracle-restore-point to use secrets (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
drobinson-moj authored Nov 30, 2023
1 parent 55ae41b commit f65dc72
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 83 deletions.
6 changes: 3 additions & 3 deletions ansible/roles/oracle-restore-point/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ SYS user database Passwords stored in SSM parameter store.
1. Create Restore point

```
no_proxy="*" ansible-playbook site.yml --limit t1-nomis-db-1-a -e force_role=oracle-restore-point -e restore_point_name=PRE_ROLE_RUN -e db_tns_list=T1MIS,T1CNMAUD,T1CNOM -e action=create
no_proxy="*" ansible-playbook site.yml --limit t1-nomis-db-1-a -e force_role=oracle-restore-point -e restore_point_name=PRE_ROLE_RUN -e db_tns_list=T1MIS,T1CNMAUD,T1CNOM --tags create_restore_point
```

2. Drop restore point

```
no_proxy="*" ansible-playbook site.yml --limit t1-nomis-db-1-a -e force_role=oracle-restore-point -e restore_point_name=PRE_ROLE_RUN -e db_tns_list=T1MIS,T1CNMAUD,T1CNOM -e action=drop
```
no_proxy="*" ansible-playbook site.yml --limit t1-nomis-db-1-a -e force_role=oracle-restore-point -e restore_point_name=PRE_ROLE_RUN -e db_tns_list=T1MIS,T1CNMAUD,T1CNOM --tags drop_restore_point
```
10 changes: 2 additions & 8 deletions ansible/roles/oracle-restore-point/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
stage: /u02/stage
oracle_install_user: oracle
oracle_install_group: oinstall
use_ssm_params: false
db_secretsmanager_passwords:
db:
parameter: "/oracle/database/{{ db_name }}/passwords"
secret: "/oracle/database/{{ db_name }}/passwords"
users:
- sys:

db_ssm_passwords: "{{ db_secretsmanager_passwords }}"
#db_tns_list: # comma separate listed of db names that must be defined in db_configs. Pass in via cmdline
db_configs: {}
25 changes: 25 additions & 0 deletions ansible/roles/oracle-restore-point/tasks/create_restore_point.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
---
- name: Set DB facts
set_fact:
db_sid: "{{ db_configs[ db_name ].instance_name }}"
db_passwords_secret: "/oracle/database/{{ db_name }}/passwords"

- name: Get DB secrets {{ db_passwords_secret }}
set_fact:
db_passwords: "{{ lookup('amazon.aws.aws_secret', db_passwords_secret) }}"

- name: Get DB sys password
set_fact:
db_sys_password: "{{ db_passwords.sys }}"

- name: Check password is extracted
ansible.builtin.set_fact:
db_sys_password_set: true
when:
- db_sys_password |length > 0
- db_sid |length > 0

- name: Fail if missing secrets
ansible.builtin.fail:
msg: Ensure SYS password exists for {{ db_name }} database
when: not db_sys_password_set |default(false)

- name: Copy restore point creation script
ansible.builtin.template:
src: "create_restore_point.sql.j2"
Expand Down
27 changes: 27 additions & 0 deletions ansible/roles/oracle-restore-point/tasks/drop_restore_point.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
---
- name: Set DB facts
set_fact:
db_sid: "{{ db_configs[ db_name ].instance_name }}"
db_passwords_secret: "/oracle/database/{{ db_name }}/passwords"

- name: Get DB secrets {{ db_passwords_secret }}
set_fact:
db_passwords: "{{ lookup('amazon.aws.aws_secret', db_passwords_secret) }}"

- name: Get DB sys password
set_fact:
db_sys_password: "{{ db_passwords.sys }}"

- name: Check password is extracted
ansible.builtin.set_fact:
db_sys_password_set: true
when:
- db_sys_password |length > 0
- db_sid |length > 0

- name: Fail if missing secrets
ansible.builtin.fail:
msg: Ensure SYS password exists for {{ db_name }} database
when: not db_sys_password_set |default(false)
- set_fact:
db_passwords_secret: "/oracle/database/{{ db_name }}/passwords"

- name: Copy drop restore point script
ansible.builtin.template:
src: "drop_restore_point.sql.j2"
Expand Down
65 changes: 0 additions & 65 deletions ansible/roles/oracle-restore-point/tasks/get_facts.yml

This file was deleted.

17 changes: 10 additions & 7 deletions ansible/roles/oracle-restore-point/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
---
- name: Get facts for playbook execution
ansible.builtin.import_tasks: get_facts.yml
tags:
- always

- name: Create restore point on databases specified by TNS
ansible.builtin.include_tasks:
file: create_restore_point.yml
apply:
tags:
- create_restore_point
- never
loop_control:
loop_var: db_name
loop: "{{ db_tns_list.split(',') }}"
when: db_server_file.stat.exists and db_tns_list is defined and restore_point_name is defined and action == "create"
tags:
- create_restore_point
- never
when: db_tns_list is defined and restore_point_name is defined

- name: Drop restore point from databases specified by TNS
ansible.builtin.include_tasks:
file: drop_restore_point.yml
apply:
tags:
- drop_restore_point
- never
loop_control:
loop_var: db_name
loop: "{{ db_tns_list.split(',') }}"
when: db_server_file.stat.exists and db_tns_list is defined and restore_point_name is defined and action == "drop"
tags:
- drop_restore_point
- never
when: db_tns_list is defined and restore_point_name is defined

0 comments on commit f65dc72

Please sign in to comment.