diff --git a/plugins/action/zos_copy.py b/plugins/action/zos_copy.py index bd6335017f..81d6d37433 100644 --- a/plugins/action/zos_copy.py +++ b/plugins/action/zos_copy.py @@ -323,20 +323,15 @@ def _copy_to_remote(self, src, is_dir=False, ignore_stderr=False, task_vars=None """Copy a file or directory to the remote z/OS system """ self.tmp_dir = self._connection._shell._options.get("remote_tmp") temp_path = os.path.join(self.tmp_dir, _create_temp_path_name()) - - rc, stdout, stderr = self._connection.exec_command("mkdir -p {0}".format(temp_path)) - display.vvv(f"ibm_zos_copy: remote mkdir result {rc}, {stdout}, {stderr} path {temp_path}") - if rc > 0: - msg = f"Failed to create remote temporary directory in {self.tmp_dir}. Ensure that user has proper access." - return self._exit_action({}, msg, failed=True) - - # The temporary dir was created successfully using ssh connection user. - rc, stdout, stderr = self._connection.exec_command(F"cd {temp_path} && pwd") - display.vvv(f"ibm_zos_copy: remote pwd result {rc}, {stdout}, {stderr} path {temp_path}") - if rc > 0: - msg = f"Failed to resolve remote temporary directory {temp_path}. Ensure that user has proper access." - return self._exit_action({}, msg, failed=True) - temp_path = stdout.decode("utf-8").replace("\r", "").replace("\n", "") + tempfile_args = {"path": temp_path, "state": "directory"} + # Reverted this back to using file ansible module so ansible would handle all temporary dirs + # creation with correct permissions. + display.vvv(f"Using ansible module file to create a temp dir in path {temp_path}") + tempfile = self._execute_module( + module_name="file", module_args=tempfile_args, task_vars=task_vars, wrap_async=self._task.async_val + ) + display.vvv(f"Module file result {tempfile}") + temp_path = tempfile["path"] _sftp_action = 'put'