Skip to content

Commit

Permalink
Add error handling and formatting for assemble_cluster_template
Browse files Browse the repository at this point in the history
Signed-off-by: Webster Mudge <[email protected]>
  • Loading branch information
wmudge committed Nov 17, 2023
1 parent c3e5093 commit acd69dd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions plugins/action/assemble_cluster_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2023 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -189,7 +186,12 @@ def run(self, tmp=None, task_vars=None):
# Compile the regexp
compiled = None
if regexp is not None:
compiled = re.compile(regexp)
try:
compiled = re.compile(regexp)
except re.error as e:
raise AnsibleActionFail(
message=f"Regular expression, {regexp}, is invalid: {to_native(e)}"
)

# Assemble the src files into output file
with tempfile.NamedTemporaryFile(
Expand Down Expand Up @@ -231,15 +233,15 @@ def run(self, tmp=None, task_vars=None):

if assembled_checksum != dest_stat["checksum"]:
diff = {}

if self._task.diff:
diff = self._get_diff_data(dest, assembled.name, task_vars)

# Define a temporary remote path for the remote copy
remote_path = self._connection._shell.join_path(
self._connection._shell.tmpdir, "assembled_cluster_template"
)

# Transfer the file to the remote path
transfered = self._transfer_file(assembled.name, remote_path)

Expand All @@ -262,7 +264,7 @@ def run(self, tmp=None, task_vars=None):

if diff:
copy.update(diff=diff)

result.update(copy)
else:
# Gather details on the existing file
Expand All @@ -271,7 +273,7 @@ def run(self, tmp=None, task_vars=None):
module_args=submodule_args,
task_vars=task_vars,
)

result.update(file)
except AnsibleAction as e:
result.update(e.result)
Expand Down

0 comments on commit acd69dd

Please sign in to comment.