Skip to content

Commit b01cf52

Browse files
committed
New role: oradb-manage-db
Uses loop_control to iterate over the oracle_databases structure This role will replace oradb-create/oradb-delete. pre-reqs: Ansible version >= 2.1 (Tested with 2.4 & 2.5). It uses the same variable structure as the old roles, but adapted to use loop_control
1 parent 2641576 commit b01cf52

16 files changed

+7496
-0
lines changed

roles/oradb-manage-db/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Role Name
2+
=========
3+
4+
A brief description of the role goes here.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
10+
11+
Role Variables
12+
--------------
13+
14+
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
15+
16+
Dependencies
17+
------------
18+
19+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
20+
21+
Example Playbook
22+
----------------
23+
24+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25+
26+
- hosts: servers
27+
roles:
28+
- { role: username.rolename, x: 42 }
29+
30+
License
31+
-------
32+
33+
BSD
34+
35+
Author Information
36+
------------------
37+
38+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
3+
hostgroup: "{{ group_names[0] }}"
4+
oracle_dbca_rsp: "dbca_{{ dbh.oracle_db_name }}.rsp" # Name of responsefile used by dbca. One per database
5+
oracle_netca_rsp: "netca_{{ item.home }}_{{ listener_name_template }}.rsp"
6+
oracle_user: oracle # User that will own the Oracle Installations.
7+
oracle_user_home: "/home/{{ oracle_user }}" # Home directory for oracle_user. Needed for passing in ssh-keys, profiles etc
8+
oracle_group: oinstall # Primary group for oracle_user.
9+
oracle_dba_group: dba # Primary group for oracle_user.
10+
grid_dba_group: asmdba # Primary group for oracle_user.
11+
12+
#oracle_home_db: "{% if item.oracle_home is defined %}{{ item.oracle_home}}{% else %}{{ oracle_base }}/{{ item.oracle_version_db }}/{{ item.home }}{% endif %}{% else %}{% if db.oracle_home is defined %}{{ db.oracle_home }}{% else %}{{ oracle_base }}/{{ db.oracle_version_db }}/{{ db.home }}{% endif %}"
13+
#oracle_home_db: "{% if db is defined %}{% if db.oracle_home is defined %}{{db.oracle_home}}{% if item is defined }{% else %}{{ db.oracle_home}}{{ oracle_base }}/{{ db.oracle_version_db }}/{{ db.home }}{% endif %}{% endif %}"
14+
#oracle_home_db: "{% if item.0 is defined %}{% if item.0.oracle_home is defined %}{{ item.0.oracle_home}}{% else %}{{ oracle_base }}/{{ item.0.oracle_version_db }}/{{ item.0.home }}{% endif %}{% else %}{% if item.oracle_home is defined %}{{ item.oracle_home }}{% else %}{{ oracle_base }}/{{ item.oracle_version_db }}/{{ item.home }}{% endif %}{% endif %}"
15+
oracle_home_db: "{% if item is defined %}{% if item.oracle_home is defined %}{{ item.oracle_home}}{% else %}{{ oracle_base }}/{{ item.oracle_version_db }}/{{ item.home }}{% endif %}{% else %}{% if dbh.oracle_home is defined %}{{ dbh.oracle_home }}{% else %}{{ oracle_base }}/{{ dbh.oracle_version_db }}/{{ dbh.home }}{% endif %}{% endif %}"
16+
17+
oracle_env_dbca:
18+
ORACLE_HOME: "{{ oracle_home_db}}"
19+
LD_LIBRARY_PATH: "{{ oracle_home_db}}/lib"
20+
21+
oracle_stage: /u01/stage
22+
oracle_rsp_stage: "{{ oracle_stage }}/rsp"
23+
oracle_inventory_loc: /u01/app/oraInventory
24+
oracle_base: /u01/app/oracle
25+
oracle_profile_name: ".profile_{{ item.oracle_db_name }}" # Name of profile-file. Sets up the environment for that database. One per database
26+
oracle_dbf_dir_fs: /u01/oradata/ # If storage_type=FS this is where the database is placed.
27+
oracle_reco_dir_fs: /u01/fra/ # If storage_type=FS this is where the fast recovery area is placed.
28+
oracle_dbf_dir_asm: '+DATA' # If storage_type=ASM this is where the database is placed.
29+
oracle_reco_dir_asm: '+FRA' # If storage_type=ASM this is where the fast recovery area is placed
30+
datafile_dest: "{% if dbh.storage_type|upper == 'FS' %}{{ oracle_dbf_dir_fs }}{% elif dbh.storage_type|upper == 'ASM' %}{{ oracle_dbf_dir_asm }}{% else %}{% endif %}"
31+
recoveryfile_dest: "{% if dbh.storage_type|upper == 'FS' %}{{ oracle_reco_dir_fs }}{% elif dbh.storage_type|upper == 'ASM' %}{{ oracle_reco_dir_asm }}{% else %}{% endif %}"
32+
# datafile_dest: "{% if item.0.storage_type|upper == 'FS' %}{{ oracle_dbf_dir_fs }}{% elif item.0.storage_type|upper == 'ASM' %}{{ oracle_dbf_dir_asm }}{% else %}{% endif %}"
33+
# recoveryfile_dest: "{% if item.0.storage_type|upper == 'FS' %}{{ oracle_reco_dir_fs }}{% elif item.0.storage_type|upper == 'ASM' %}{{ oracle_reco_dir_asm }}{% else %}{% endif %}"
34+
35+
configure_cluster: false
36+
#oracle_install_option_gi: "none"
37+
oracle_gi_cluster_type: STANDARD
38+
hostgroup_hub: "{{ hostgroup }}-hub"
39+
hostgroup_leaf: "{{ hostgroup }}-leaf"
40+
create_listener: "{% if oracle_install_option_gi is defined %}False{% elif oracle_install_option_gi is undefined %}{% if item.listener_name is defined %}True{% else %}False{% endif %}{% endif %}"
41+
listener_name_template: "{% if item.listener_name is defined %}{{ item.listener_name }}{% else %}{{ listener_name }}{% endif %}"
42+
listener_protocols_template: "{% if item.listener_protocols is defined %}{{ item.listener_protocols }}{% else %}{{ listener_protocols }}{% endif %}"
43+
listener_port_template: "{% if item.listener_port is defined %}{{ item.listener_port }}{% else %}{{ listener_port }}{% endif %}"
44+
listener_name: LISTENER
45+
listener_protocols: TCP
46+
listener_port: 1521
47+
autostartup_service: false
48+
49+
50+
# Everything between the lines START-OF-PASSWORDS & END-OF-PASSWORDS can be
51+
# put in an external passwords.yml file and be encrypted by Vault.
52+
# The file should be put in 'group_vars/<your-config>/passwords.yml'
53+
# This example will be broken out to a passwords.yml as soon as is allowed in ansible
54+
55+
## START-OF-PASSWORDS
56+
# GI
57+
default_gipass: "{% if oracle_password is defined %}{{ oracle_password }}{% else %}Oracle123{% endif%}" # The check for the old passwords are there for backwards compatibility and only temporary, will be removed
58+
sysasmpassword: "{% if oracle_password is defined %}{{ oracle_password }}{% else %}Oracle123{% endif%}" # The check for the old passwords are there for backwards compatibility and only temporary, will be removed
59+
asmmonitorpassword: "{% if oracle_password is defined %}{{ oracle_password }}{% else %}Oracle123{% endif%}" # The check for the old passwords are there for backwards compatibility and only temporary, will be removed
60+
# DB
61+
default_dbpass: "{% if item is defined %}{% if item.oracle_db_passwd is defined %}{{ item.oracle_db_passwd}}{% endif %}{% elif dbh is defined %}{% if dbh.oracle_db_passwd is defined %}{{ dbh.oracle_db_passwd }}{% endif %}{% else %}Oracle_123{% endif %}"
62+
dbpasswords:
63+
orcl:
64+
sys: Oracle_456
65+
system: Oracle_456
66+
dbsnmp: Oracle_456
67+
pdbadmin: Oracle_456
68+
69+
## END-OF-PASSWORDS
70+
71+
dbca_templatename: General_Purpose.dbc
72+
dbca_initParams: "{% if '12.2' in dbh.oracle_version_db %} -initParams db_name={{dbh.oracle_db_name}}{% if dbh.oracle_db_unique_name is defined %},db_unique_name={{dbh.oracle_db_unique_name}}{% endif %}{% endif %}"
73+
dbca_sys_pass: "{% if dbpasswords[dbh.oracle_db_name] is defined %}{% if dbpasswords[dbh.oracle_db_name]['sys'] is defined %}{{dbpasswords[dbh.oracle_db_name]['sys']}}{% else %}{{default_dbpass}}{% endif %}{% else %}{{default_dbpass}}{% endif %}"
74+
dbca_redolog: "{% if dbh.redolog_size_in_mb is defined %} -redoLogFileSize {{dbh.redolog_size_in_mb}}{% endif %}"
75+
76+
# This is an example layout of a database installation
77+
oracle_databases: # Dictionary describing the databases to be installed
78+
- home: db1 # 'Last' directory in ORACLE_HOME path (e.g /u01/app/oracle/12.1.0.2/racdb)
79+
oracle_version_db: 12.2.0.1 # Oracle versiono
80+
oracle_edition: EE # The edition of database-server (EE,SE,SEONE)
81+
oracle_db_name: orcl # Database name
82+
oracle_db_type: SI # Type of database (RAC,RACONENODE,SI)
83+
is_container: False # (true/false) Is the database a container database
84+
pdb_prefix: pdb
85+
num_pdbs: 1
86+
storage_type: FS # Database storage to be used. ASM or FS.
87+
service_name: orcl_serv # Inital service to be created (not in use yet)
88+
oracle_init_params: "" # Specific parameters to be set during installation. Comma-separated list
89+
oracle_db_mem_totalmb: 1024 # Amount of RAM to be used for SGA + PGA
90+
oracle_database_type: MULTIPURPOSE # MULTIPURPOSE|DATA_WAREHOUSING|OLTP
91+
redolog_size_in_mb: 100
92+
listener_name: LISTENER
93+
state: present # present | absent
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- name: listener | Create responsefile for listener configuration
2+
template: src=netca.rsp.{{ item.oracle_version_db }}.j2 dest={{ oracle_rsp_stage }}/{{ oracle_netca_rsp }}
3+
become: true
4+
become_user: "{{ oracle_user }}"
5+
with_items:
6+
- "{{ oracle_databases }}"
7+
when: create_listener
8+
tags: responsefile_netca, listener_install
9+
10+
- name: listener | Create listener
11+
shell: "{{ oracle_home_db }}/bin/netca -responseFile {{ oracle_rsp_stage }}/{{ oracle_netca_rsp }} -silent"
12+
with_items:
13+
- "{{ oracle_databases }}"
14+
args:
15+
creates: "{{ oracle_home_db }}/network/admin/listener.ora"
16+
become: true
17+
become_user: "{{ oracle_user }}"
18+
when: create_listener
19+
tags: listener_install
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# tasks file for manage-db
3+
4+
- name: manage-db | set fact for Listener
5+
set_fact:
6+
create_listener: "{{ create_listener }}"
7+
with_items: "{{ oracle_databases }}"
8+
tags: set_fact
9+
10+
- include: listener.yml
11+
when: create_listener
12+
tags: listener
13+
14+
- name: manage-db | Copy custom dbca Templates to ORACLE_HOME/assistants/dbca/templates
15+
template:
16+
src={{ item.dbca_templatename }}
17+
dest={{ oracle_home_db }}/assistants/dbca/templates/{{ item.dbca_templatename }}
18+
owner={{ oracle_user }}
19+
group={{ oracle_group }}
20+
mode=640
21+
with_items:
22+
- "{{oracle_databases}}"
23+
when: item.dbca_templatename is defined and item.dbca_templatename not in('New_Database.dbt','General_Purpose.dbc')
24+
tags:
25+
- customdbcatemplate
26+
27+
- include: manage-db.yml
28+
with_items:
29+
- "{{ oracle_databases }}"
30+
loop_control:
31+
loop_var: dbh
32+
when: oracle_databases is defined
33+
tags: create_db,dbca
34+
35+
36+
- name: manage-db | Check if database is running
37+
shell: ps -ef |grep pmon |grep -v grep
38+
tags:
39+
- psout
40+
register: psout
41+
changed_when: False
42+
failed_when: False
43+
ignore_errors: True
44+
45+
46+
- debug: var=psout.stdout_lines
47+
changed_when: False
48+
failed_when: False
49+
when: psout is defined
50+
tags:
51+
- psout
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
- name: manage-db | print oracle_db_name
2+
debug: msg="DB-name is {{dbh.oracle_db_name}}, state is {{ dbh.state}}"
3+
run_once: "{{ configure_cluster }}"
4+
5+
- name: manage-db | check if GI is present
6+
stat: path=/etc/oracle/olr.loc_xxxx
7+
register: olrloc
8+
#
9+
# - name: manage-db | check if database exists (GI)
10+
# shell: "{{ oracle_home_db }}/bin/srvctl config database | grep -w {{ dbh.oracle_db_name}}"
11+
# environment: "{{ oracle_env_dbca }}"
12+
# run_once: "{{ configure_cluster }}"
13+
# register: existing_dbs
14+
# changed_when: False
15+
# failed_when: False
16+
# when: olrloc.stat.exists
17+
# tags: create_db,dbcatemplate,debug
18+
19+
- name: manage-db | check if database exists (NO GI)
20+
shell: "cat /etc/oratab | grep -w {{ dbh.oracle_db_name }}:{{ oracle_home_db }} |grep -v \"^#\"|cut -f1 -d: -s"
21+
environment: "{{ oracle_env_dbca }}"
22+
run_once: "{{ configure_cluster }}"
23+
register: existing_dbs
24+
changed_when: False
25+
failed_when: False
26+
when: not olrloc.stat.exists
27+
tags: create_db,dbcatemplate,debug
28+
29+
#- debug: var=existing_dbs.stdout_lines
30+
31+
- name: manage-db | add dotprofile
32+
template:
33+
src: dotprofile-db.j2
34+
dest: "/home/{{ oracle_user}}/.profile_{{ dbh.oracle_db_name }}"
35+
owner: "{{ oracle_user }}"
36+
group: "{{ oracle_group }}"
37+
mode: 0660
38+
when: dbh.state|lower == 'present'
39+
tags: create_db,dotprofile_db
40+
41+
- name: manage-db | Prepare installation template
42+
template:
43+
src: "dbca-create-db.rsp.{{ dbh.oracle_version_db}}.j2"
44+
dest: "{{ oracle_rsp_stage }}/{{ oracle_dbca_rsp }}"
45+
owner: "{{ oracle_user }}"
46+
group: "{{ oracle_group }}"
47+
mode: 0660
48+
run_once: "{{ configure_cluster }}"
49+
when: dbh.oracle_db_name not in existing_dbs.stdout and dbh.state|lower == 'present'
50+
tags: create_db,dbcatemplate
51+
52+
- name: manage-db | create database
53+
shell: "time {{oracle_home_db}}/bin/dbca -createDatabase -responseFile {{ oracle_rsp_stage }}/{{ oracle_dbca_rsp }} -silent {{ dbca_redolog }} {{ dbca_initParams }}"
54+
run_once: "{{ configure_cluster }}"
55+
become_user: "{{ oracle_user }}"
56+
when: dbh.oracle_db_name not in existing_dbs.stdout and dbh.state|lower == 'present'
57+
register: dbca_create
58+
tags: create_db,dbca
59+
60+
- debug: var=dbca_create.stdout_lines
61+
when: dbca_create.changed
62+
63+
- name: manage-db |Customize oratab for autostart
64+
lineinfile:
65+
dest=/etc/oratab
66+
line="{{ dbh.oracle_db_name }}:{{ oracle_home_db }}:Y"
67+
state=present
68+
when: autostartup_service and not olrloc.stat.exists
69+
tags: update_oratab
70+
71+
- name: manage-db |Customize oratab for autostart
72+
lineinfile:
73+
dest=/etc/oratab
74+
line="{{ dbh.oracle_db_name }}:{{ oracle_home_db }}:N"
75+
state=absent
76+
when: autostartup_service and not olrloc.stat.exists
77+
become: yes
78+
tags: update_oratab
79+
80+
- name: manage-db | remove database
81+
shell: "{{oracle_home_db}}/bin/dbca -deleteDatabase -silent -sourceDB {{ dbh.oracle_db_name }} -sysDBAUserName sys -sysDBAPassword {{ dbca_sys_pass}}"
82+
run_once: "{{ configure_cluster }}"
83+
become_user: "{{ oracle_user }}"
84+
when: dbh.oracle_db_name in existing_dbs.stdout and dbh.state|lower == 'absent'
85+
register: dbca_remove
86+
tags: create_cdb,dbca
87+
88+
- debug: var=dbca_remove.stdout_lines
89+
when: dbca_remove.changed
90+
91+
- name: manage-db | remove dotprofile
92+
file:
93+
path: "/home/{{ oracle_user}}/.profile_{{ dbh.oracle_db_name }}"
94+
state: absent
95+
when: dbh.state|lower == 'absent'
96+
tags: create_cdb,dotprofile_db

0 commit comments

Comments
 (0)