From cb67235eabdce502a84f5ce7e4b0aa6c8f45c226 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 25 Feb 2019 16:46:33 +0530 Subject: [PATCH] Fix network config module invalid src option error (#52912) Fixes #52911 Raise AnsibleError execption if the file path mentioned in src option in not found or failed to load --- lib/ansible/plugins/action/network.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/ansible/plugins/action/network.py b/lib/ansible/plugins/action/network.py index e7d7140ef9..d7b8a61f42 100644 --- a/lib/ansible/plugins/action/network.py +++ b/lib/ansible/plugins/action/network.py @@ -49,12 +49,6 @@ class ActionModule(_ActionModule): return result - def _handle_src_option(self): - try: - self._handle_template() - except ValueError as exc: - return dict(failed=True, msg=to_text(exc)) - def _handle_backup_option(self, result, task_vars): filename = None @@ -132,7 +126,7 @@ class ActionModule(_ActionModule): cwd = self._task._role._role_path return cwd - def _handle_template(self, convert_data=True): + def _handle_src_option(self, convert_data=True): src = self._task.args.get('src') working_path = self._get_working_path() @@ -144,13 +138,13 @@ class ActionModule(_ActionModule): source = self._loader.path_dwim_relative(working_path, src) if not os.path.exists(source): - raise ValueError('path specified in src not found') + raise AnsibleError('path specified in src not found') try: with open(source, 'r') as f: template_data = to_text(f.read()) - except IOError: - return dict(failed=True, msg='unable to load src file') + except IOError as e: + raise AnsibleError("unable to load src file {0}, I/O error({1}): {2}".format(source, e.errno, e.strerror)) # Create a template search path in the following order: # [working_path, self_role_path, dependent_role_paths, dirname(source)]