Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions changelogs/fragments/opatch_tmpdir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "oracle_opatch.py needs to support configurable temp directory (oravirt#462)"
69 changes: 52 additions & 17 deletions plugins/modules/oracle_opatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@
The listener port to connect to the database if using dbms_service
required: false
default: 1521

script_env:
description: >
Dictionary of environment settings to be passed to run_command
required: false
default: {}
notes:
requirements: [ "os","pwd","distutils.version" ]
author: Mikael Sandström, oravirt@gmail.com, @oravirt
Expand All @@ -114,13 +118,13 @@
'''


def get_version(module, msg, oracle_home):
def get_version(module, msg, oracle_home, script_env):
'''
Returns the DB server version
'''

def loc_exec_command(command):
(rc, stdout, stderr) = module.run_command(command)
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (
stdout,
Expand All @@ -145,13 +149,13 @@ def loc_exec_command(command):
return stdout.split(' ')[2][0:4]


def get_opatch_version(module, msg, oracle_home):
def get_opatch_version(module, msg, oracle_home, script_env):
'''
Returns the Opatch version
'''

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


def check_patch_applied(
module, msg, oracle_home, patch_id, patch_version, opatchauto, exclude_upi
module,
msg,
oracle_home,
patch_id,
patch_version,
opatchauto,
exclude_upi,
script_env,
):
'''
Gets all patches already applied and compares to the
Expand All @@ -191,7 +202,7 @@ def check_patch_applied(
oh_owner = get_file_owner(module, msg, oracle_home)
command += 'sudo -u %s ' % (oh_owner)
command += '%s/OPatch/opatch lspatches ' % (oracle_home)
(rc, stdout, stderr) = module.run_command(command)
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
# module.exit_json(msg=stdout, changed=False)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
Expand All @@ -209,7 +220,9 @@ def check_patch_applied(
return True
else:
command += ' -id %s' % patch_id
(rc, stdout, stderr) = module.run_command(command)
(rc, stdout, stderr) = module.run_command(
command, environ_update=script_env
)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (
stdout,
Expand All @@ -224,7 +237,7 @@ def check_patch_applied(
return False


def analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
def analyze_patch(module, msg, oracle_home, patch_base, opatchauto, script_env):
checks = []

if opatchauto:
Expand Down Expand Up @@ -267,7 +280,7 @@ def analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
checks.append(spacecommand)

for cmd in checks:
(rc, stdout, stderr) = module.run_command(cmd)
(rc, stdout, stderr) = module.run_command(cmd, environ_update=script_env)
# module.exit_json(msg=stdout, changed=False)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, cmd)
Expand All @@ -291,14 +304,17 @@ def apply_patch(
offline,
stop_processes,
rolling,
script_env,
output,
):
'''
Applies the patch
'''

if conflict_check:
if not analyze_patch(module, msg, oracle_home, patch_base, opatchauto):
if not analyze_patch(
module, msg, oracle_home, patch_base, opatchauto, script_env
):
module.fail_json(msg='Prereq checks failed')

if opatchauto:
Expand Down Expand Up @@ -342,7 +358,7 @@ def apply_patch(
):
command += ' -ocmrf %s' % (ocm_response_file)

(rc, stdout, stderr) = module.run_command(command)
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
module.fail_json(msg=msg, changed=False)
Expand Down Expand Up @@ -454,6 +470,7 @@ def remove_patch(
opatchauto,
ocm_response_file,
stop_processes,
script_env,
output,
):
'''
Expand Down Expand Up @@ -485,7 +502,7 @@ def remove_patch(
command += ' -ocmrf %s' % (ocm_response_file)

# module.exit_json(msg=command, changed=False)
(rc, stdout, stderr) = module.run_command(command)
(rc, stdout, stderr) = module.run_command(command, environ_update=script_env)
if rc != 0:
msg = 'Error - STDOUT: %s, STDERR: %s, COMMAND: %s' % (stdout, stderr, command)
module.fail_json(msg=msg, changed=False)
Expand Down Expand Up @@ -538,6 +555,7 @@ def main():
),
hostname=dict(required=False, default='localhost', aliases=['host']),
port=dict(required=False, type='int', default=1521),
script_env=dict(required=False, type='dict', default={}),
),
)

Expand All @@ -557,6 +575,7 @@ def main():
state = module.params["state"]
hostname = module.params["hostname"]
port = module.params["port"]
script_env = module.params["script_env"]

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

# Get the Oracle % Opatch version
major_version = get_version(module, msg, oracle_home)
opatch_version = get_opatch_version(module, msg, oracle_home)
major_version = get_version(module, msg, oracle_home, script_env)
opatch_version = get_opatch_version(module, msg, oracle_home, script_env)
opatch_version_noocm = '12.2.0.1.5'

if opatch_minversion is not None:
Expand Down Expand Up @@ -616,7 +635,14 @@ def main():

if state == 'present':
if not check_patch_applied(
module, msg, oracle_home, patch_id, patch_version, opatchauto, None
module,
msg,
oracle_home,
patch_id,
patch_version,
opatchauto,
None,
script_env,
):
if apply_patch(
module,
Expand All @@ -630,6 +656,7 @@ def main():
offline,
stop_processes,
rolling,
script_env,
output,
):
if patch_version is not None:
Expand Down Expand Up @@ -658,7 +685,14 @@ def main():

elif state == 'absent':
if check_patch_applied(
module, msg, oracle_home, patch_id, patch_version, opatchauto, exclude_upi
module,
msg,
oracle_home,
patch_id,
patch_version,
opatchauto,
exclude_upi,
script_env,
):
if remove_patch(
module,
Expand All @@ -669,6 +703,7 @@ def main():
opatchauto,
ocm_response_file,
stop_processes,
script_env,
output,
):
if patch_version is not None:
Expand Down
1 change: 1 addition & 0 deletions roles/oraswgi_manage_patches/tasks/loop_patchid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
ocm_response_file: "{{ ocm_response_file | default(omit) }}"
output: verbose
state: "{{ gip_opatch.0.state }}"
script_env: "{{ {'TMPDIR': orahost_meta_tmpdir, '_JAVA_OPTIONS': '-Djava.io.tmpdir=' + orahost_meta_java_options} }}"
become: true
become_user: "{{ __opatchauto_patchtype | ternary('root', grid_user) }}"
vars:
Expand Down