-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathdatabase.pp
182 lines (167 loc) · 7.44 KB
/
database.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# == Class: oradb::database
#
#
# action = createDatabase|deleteDatabase
# database_type = MULTIPURPOSE|DATA_WAREHOUSING|OLTP
#
define oradb::database(
$oracle_base = undef,
$oracle_home = undef,
$version = '11.2', # 11.2|12.1
$user = 'oracle',
$group = 'dba',
$download_dir = '/install',
$action = 'create',
$template = undef,
$template_seeded = undef,
$template_variables = 'dummy=/tmp', # for dbt template
$db_name = 'orcl',
$db_domain = undef,
$db_port = '1521',
$sys_password = 'Welcome01',
$system_password = 'Welcome01',
$data_file_destination = undef,
$recovery_area_destination = undef,
$character_set = 'AL32UTF8',
$nationalcharacter_set = 'UTF8',
$init_params = undef,
$sample_schema = 'TRUE',
$memory_percentage = '40',
$memory_total = '800',
$database_type = 'MULTIPURPOSE', # MULTIPURPOSE|DATA_WAREHOUSING|OLTP
$em_configuration = 'NONE', # CENTRAL|LOCAL|ALL|NONE
$storage_type = 'FS', #FS|CFS|ASM
$asm_snmp_password = 'Welcome01',
$db_snmp_password = 'Welcome01',
$asm_diskgroup = 'DATA',
$recovery_diskgroup = undef,
$cluster_nodes = undef, # comma separated list with at first the local and at second the remode host e.g. "racnode1,racnode2"
$container_database = false, # 12.1 feature for pluggable database
$puppet_download_mnt_point = undef,
)
{
if (!( $version in ['11.2','12.1'])) {
fail('Unrecognized version')
}
if $action == 'create' {
$operationType = 'createDatabase'
} elsif $action == 'delete' {
$operationType = 'deleteDatabase'
} else {
fail('Unrecognized database action')
}
if (!( $database_type in ['MULTIPURPOSE','DATA_WAREHOUSING','OLTP'])) {
fail('Unrecognized database_type')
}
if (!( $em_configuration in ['NONE','CENTRAL','LOCAL','ALL'])) {
fail('Unrecognized em_configuration')
}
if (!( $storage_type in ['FS','CFS','ASM'])) {
fail('Unrecognized storage_type')
}
if ( $version == '11.2' and $container_database == true ){
fail('container or pluggable database is not supported on version 11.2')
}
$execPath = '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin'
if $puppet_download_mnt_point == undef {
$mountPoint = 'oradb/'
} else {
$mountPoint = $puppet_download_mnt_point
}
case $::kernel {
'Linux': {
$userHome = "/home/${user}"
}
'SunOS': {
$userHome = "/export/home/${user}"
}
default: {
fail('Unrecognized operating system')
}
}
if (is_hash($init_params) or is_string($init_params)) {
if is_hash($init_params) {
$initParamsArray = sort(join_keys_to_values($init_params, '='))
$sanitizedInitParams = join($initParamsArray,',')
} else {
$sanitizedInitParams = $init_params
}
} else {
fail 'init_params only supports a String or a Hash as value type'
}
$sanitized_title = regsubst($title, '[^a-zA-Z0-9.-]', '_', 'G')
if $db_domain {
$globaldb_name = "${db_name}.${db_domain}"
} else {
$globaldb_name = $db_name
}
if ! defined(File["${download_dir}/database_${sanitized_title}.rsp"]) {
file { "${download_dir}/database_${sanitized_title}.rsp":
ensure => present,
content => template("oradb/dbca_${version}.rsp.erb"),
mode => '0770',
owner => $user,
group => $group,
before => Exec["oracle database ${title}"],
}
}
if ( $template_seeded ) {
$templatename = "${oracle_home}/assistants/dbca/templates/${template_seeded}.dbc"
} elsif ( $template ) {
$templatename = "${download_dir}/${template}_${sanitized_title}.dbt"
file { $templatename:
ensure => present,
content => template("${mountPoint}/${template}.dbt.erb"),
mode => '0775',
owner => $user,
group => $group,
before => Exec["oracle database ${title}"],
}
} else {
$templatename = undef
}
$elevation_prefix = "su - ${user} -c \"/bin/ksh -c \\\""
$elevation_suffix = "\\\"\""
if $action == 'create' {
if ( $templatename ) {
if ( $version == '11.2' or $container_database == false ) {
if ( $cluster_nodes != undef) {
$command = "${elevation_prefix}${oracle_home}/bin/dbca -silent -createDatabase -templateName ${templatename} -gdbname ${globaldb_name} -characterSet ${character_set} -responseFile NO_VALUE -sysPassword ${sys_password} -systemPassword ${system_password} -dbsnmpPassword ${db_snmp_password} -asmsnmpPassword ${asm_snmp_password} -storageType ${storage_type} -emConfiguration ${em_configuration} -nodelist ${cluster_nodes} -variables ${template_variables}${elevation_suffix}"
} else {
$command = "${elevation_prefix}${oracle_home}/bin/dbca -silent -createDatabase -templateName ${templatename} -gdbname ${globaldb_name} -characterSet ${character_set} -responseFile NO_VALUE -sysPassword ${sys_password} -systemPassword ${system_password} -dbsnmpPassword ${db_snmp_password} -asmsnmpPassword ${asm_snmp_password} -storageType ${storage_type} -emConfiguration ${em_configuration} -variables ${template_variables}${elevation_suffix}"
}
} else {
if( $cluster_nodes != undef) {
$command = "${elevation_prefix}${oracle_home}/bin/dbca -silent -createDatabase -templateName ${templatename} -gdbname ${globaldb_name} -characterSet ${character_set} -createAsContainerDatabase ${container_database} -responseFile NO_VALUE -sysPassword ${sys_password} -systemPassword ${system_password} -dbsnmpPassword ${db_snmp_password} -asmsnmpPassword ${asm_snmp_password} -storageType ${storage_type} -emConfiguration ${em_configuration} -nodelist ${cluster_nodes} -variables ${template_variables}${elevation_suffix}"
} else {
$command = "${elevation_prefix}${oracle_home}/bin/dbca -silent -createDatabase -templateName ${templatename} -gdbname ${globaldb_name} -characterSet ${character_set} -createAsContainerDatabase ${container_database} -responseFile NO_VALUE -sysPassword ${sys_password} -systemPassword ${system_password} -dbsnmpPassword ${db_snmp_password} -asmsnmpPassword ${asm_snmp_password} -storageType ${storage_type} -emConfiguration ${em_configuration} -variables ${template_variables}${elevation_suffix}"
}
}
} else {
$command = "${elevation_prefix}${oracle_home}/bin/dbca -silent -responseFile ${download_dir}/database_${sanitized_title}.rsp${elevation_suffix}"
}
exec { "oracle database ${title}":
command => $command,
creates => "${oracle_base}/admin/${db_name}",
timeout => 0,
path => $execPath,
user => 'root',
group => 'root',
cwd => $oracle_base,
environment => ["USER=${user}",],
logoutput => true,
}
} elsif $action == 'delete' {
exec { "oracle database ${title}":
command => "${oracle_home}/bin/dbca -silent -responseFile ${download_dir}/database_${sanitized_title}.rsp",
onlyif => "ls ${oracle_base}/admin/${db_name}",
timeout => 0,
path => $execPath,
user => $user,
group => $group,
cwd => $oracle_base,
environment => ["USER=${user}",],
logoutput => true,
}
}
}