Skip to content

Commit ebea497

Browse files
Thilo SolbrigRendanic
authored andcommitted
oracle_opatch.py needs to support configurable temp directory (enhances fix for #452)
1 parent 07a6882 commit ebea497

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed

plugins/modules/oracle_opatch.py

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@
103103
The listener port to connect to the database if using dbms_service
104104
required: false
105105
default: 1521
106-
106+
script_env:
107+
description: >
108+
Dictionary of environment settings to be passed to run_command
109+
required: false
110+
default: {}
107111
notes:
108112
requirements: [ "os","pwd","distutils.version" ]
109113
author: Mikael Sandström, oravirt@gmail.com, @oravirt
@@ -114,13 +118,13 @@
114118
'''
115119

116120

117-
def get_version(module, msg, oracle_home):
121+
def get_version(module, msg, oracle_home, script_env):
118122
'''
119123
Returns the DB server version
120124
'''
121125

122126
def loc_exec_command(command):
123-
(rc, stdout, stderr) = module.run_command(command)
127+
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
124128
if rc != 0:
125129
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (
126130
stdout,
@@ -145,13 +149,13 @@ def loc_exec_command(command):
145149
return stdout.split(' ')[2][0:4]
146150

147151

148-
def get_opatch_version(module, msg, oracle_home):
152+
def get_opatch_version(module, msg, oracle_home, script_env):
149153
'''
150154
Returns the Opatch version
151155
'''
152156

153157
command = '%s/OPatch/opatch version' % (oracle_home)
154-
(rc, stdout, stderr) = module.run_command(command)
158+
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
155159
if rc != 0:
156160
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
157161
module.fail_json(msg=msg, changed=False)
@@ -179,7 +183,14 @@ def get_file_owner(module, msg, oracle_home):
179183

180184

181185
def check_patch_applied(
182-
module, msg, oracle_home, patch_id, patch_version, opatchauto, exclude_upi
186+
module,
187+
msg,
188+
oracle_home,
189+
patch_id,
190+
patch_version,
191+
opatchauto,
192+
exclude_upi,
193+
script_env,
183194
):
184195
'''
185196
Gets all patches already applied and compares to the
@@ -191,7 +202,7 @@ def check_patch_applied(
191202
oh_owner = get_file_owner(module, msg, oracle_home)
192203
command += 'sudo -u %s ' % (oh_owner)
193204
command += '%s/OPatch/opatch lspatches ' % (oracle_home)
194-
(rc, stdout, stderr) = module.run_command(command)
205+
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
195206
# module.exit_json(msg=stdout, changed=False)
196207
if rc != 0:
197208
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
@@ -209,7 +220,9 @@ def check_patch_applied(
209220
return True
210221
else:
211222
command += ' -id %s' % patch_id
212-
(rc, stdout, stderr) = module.run_command(command)
223+
(rc, stdout, stderr) = module.run_command(
224+
command, environ_update=script_env
225+
)
213226
if rc != 0:
214227
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (
215228
stdout,
@@ -224,7 +237,7 @@ def check_patch_applied(
224237
return False
225238

226239

227-
def analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
240+
def analyze_patch(module, msg, oracle_home, patch_base, opatchauto, script_env):
228241
checks = []
229242

230243
if opatchauto:
@@ -267,7 +280,7 @@ def analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
267280
checks.append(spacecommand)
268281

269282
for cmd in checks:
270-
(rc, stdout, stderr) = module.run_command(cmd)
283+
(rc, stdout, stderr) = module.run_command(cmd, environ_update=script_env)
271284
# module.exit_json(msg=stdout, changed=False)
272285
if rc != 0:
273286
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, cmd)
@@ -291,14 +304,17 @@ def apply_patch(
291304
offline,
292305
stop_processes,
293306
rolling,
307+
script_env,
294308
output,
295309
):
296310
'''
297311
Applies the patch
298312
'''
299313

300314
if conflict_check:
301-
if not analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
315+
if not analyze_patch(
316+
module, msg, oracle_home, patch_base, opatchauto, script_env
317+
):
302318
module.fail_json(msg='Prereq checks failed')
303319

304320
if opatchauto:
@@ -342,7 +358,7 @@ def apply_patch(
342358
):
343359
command += ' -ocmrf %s' % (ocm_response_file)
344360

345-
(rc, stdout, stderr) = module.run_command(command)
361+
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
346362
if rc != 0:
347363
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
348364
module.fail_json(msg=msg, changed=False)
@@ -454,6 +470,7 @@ def remove_patch(
454470
opatchauto,
455471
ocm_response_file,
456472
stop_processes,
473+
script_env,
457474
output,
458475
):
459476
'''
@@ -485,7 +502,7 @@ def remove_patch(
485502
command += ' -ocmrf %s' % (ocm_response_file)
486503

487504
# module.exit_json(msg=command, changed=False)
488-
(rc, stdout, stderr) = module.run_command(command)
505+
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
489506
if rc != 0:
490507
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
491508
module.fail_json(msg=msg, changed=False)
@@ -538,6 +555,7 @@ def main():
538555
),
539556
hostname=dict(required=False, default='localhost', aliases=['host']),
540557
port=dict(required=False, type='int', default=1521),
558+
script_env=dict(required=False, type='dict', default={}),
541559
),
542560
)
543561

@@ -557,6 +575,7 @@ def main():
557575
state = module.params["state"]
558576
hostname = module.params["hostname"]
559577
port = module.params["port"]
578+
script_env = module.params["script_env"]
560579

561580
if not os.path.exists(oracle_home):
562581
msg = 'oracle_home: %s doesn\'t exist' % (oracle_home)
@@ -587,8 +606,8 @@ def main():
587606
module.fail_json(msg=msg, changed=False)
588607

589608
# Get the Oracle % Opatch version
590-
major_version = get_version(module, msg, oracle_home)
591-
opatch_version = get_opatch_version(module, msg, oracle_home)
609+
major_version = get_version(module, msg, oracle_home, script_env)
610+
opatch_version = get_opatch_version(module, msg, oracle_home, script_env)
592611
opatch_version_noocm = '12.2.0.1.5'
593612

594613
if opatch_minversion is not None:
@@ -616,7 +635,14 @@ def main():
616635

617636
if state == 'present':
618637
if not check_patch_applied(
619-
module, msg, oracle_home, patch_id, patch_version, opatchauto, None
638+
module,
639+
msg,
640+
oracle_home,
641+
patch_id,
642+
patch_version,
643+
opatchauto,
644+
None,
645+
script_env,
620646
):
621647
if apply_patch(
622648
module,
@@ -630,6 +656,7 @@ def main():
630656
offline,
631657
stop_processes,
632658
rolling,
659+
script_env,
633660
output,
634661
):
635662
if patch_version is not None:
@@ -658,7 +685,14 @@ def main():
658685

659686
elif state == 'absent':
660687
if check_patch_applied(
661-
module, msg, oracle_home, patch_id, patch_version, opatchauto, exclude_upi
688+
module,
689+
msg,
690+
oracle_home,
691+
patch_id,
692+
patch_version,
693+
opatchauto,
694+
exclude_upi,
695+
script_env,
662696
):
663697
if remove_patch(
664698
module,
@@ -669,6 +703,7 @@ def main():
669703
opatchauto,
670704
ocm_response_file,
671705
stop_processes,
706+
script_env,
672707
output,
673708
):
674709
if patch_version is not None:

roles/oraswgi_manage_patches/tasks/loop_patchid.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ocm_response_file: "{{ ocm_response_file | default(omit) }}"
5656
output: verbose
5757
state: "{{ gip_opatch.0.state }}"
58+
script_env: "{{ {'TMPDIR': orahost_meta_tmpdir, '_JAVA_OPTIONS': '-Djava.io.tmpdir=' + orahost_meta_java_options} }}"
5859
become: true
5960
become_user: "{{ __opatchauto_patchtype | ternary('root', grid_user) }}"
6061
vars:

0 commit comments

Comments
 (0)