From 387093a0d6f611f2c720a16d769adbacf090ec5b Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Fri, 10 May 2019 01:12:17 +0530 Subject: [PATCH] Backport PR for fixing net_get and net_put task run failure (#56160) * Fix net_get and net_put task run failure (#56145) * net_get and net_put action plugin class need to inherit from ActionBase class as the action class implements the entire get and put logic (cherry picked from commit 9271b4e368d663b5c6db9a99bd4d89395c7799a2) * backport changelog Signed-off-by: Sumit Jaiswal --- .../56145-ios-net_get-net_put-update.yaml | 2 ++ lib/ansible/plugins/action/net_get.py | 28 +++++++++++++++++-- lib/ansible/plugins/action/net_put.py | 26 +++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/56145-ios-net_get-net_put-update.yaml diff --git a/changelogs/fragments/56145-ios-net_get-net_put-update.yaml b/changelogs/fragments/56145-ios-net_get-net_put-update.yaml new file mode 100644 index 00000000000..953fc4d7475 --- /dev/null +++ b/changelogs/fragments/56145-ios-net_get-net_put-update.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix net_get and net_put task run failure - https://github.com/ansible/ansible/pull/56145 diff --git a/lib/ansible/plugins/action/net_get.py b/lib/ansible/plugins/action/net_get.py index af421029f01..9ba8c2aaff3 100644 --- a/lib/ansible/plugins/action/net_get.py +++ b/lib/ansible/plugins/action/net_get.py @@ -23,16 +23,17 @@ import re import uuid import hashlib +from ansible.errors import AnsibleError from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.connection import Connection -from ansible.plugins.action.network import ActionModule as NetworkActionModule +from ansible.plugins.action import ActionBase from ansible.module_utils.six.moves.urllib.parse import urlsplit from ansible.utils.display import Display display = Display() -class ActionModule(NetworkActionModule): +class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): socket_path = None @@ -48,7 +49,7 @@ class ActionModule(NetworkActionModule): return result try: - src = self._task.args.get('src') + src = self._task.args['src'] except KeyError as exc: return {'failed': True, 'msg': 'missing required argument: %s' % exc} @@ -152,3 +153,24 @@ class ActionModule(NetworkActionModule): return False else: return True + + def _get_working_path(self): + cwd = self._loader.get_basedir() + if self._task._role is not None: + cwd = self._task._role._role_path + return cwd + + def _get_network_os(self, task_vars): + if 'network_os' in self._task.args and self._task.args['network_os']: + display.vvvv('Getting network OS from task argument') + network_os = self._task.args['network_os'] + elif self._play_context.network_os: + display.vvvv('Getting network OS from inventory') + network_os = self._play_context.network_os + elif 'network_os' in task_vars.get('ansible_facts', {}) and task_vars['ansible_facts']['network_os']: + display.vvvv('Getting network OS from fact') + network_os = task_vars['ansible_facts']['network_os'] + else: + raise AnsibleError('ansible_network_os must be specified on this host') + + return network_os diff --git a/lib/ansible/plugins/action/net_put.py b/lib/ansible/plugins/action/net_put.py index 1260e67f391..bf6dd52d292 100644 --- a/lib/ansible/plugins/action/net_put.py +++ b/lib/ansible/plugins/action/net_put.py @@ -25,16 +25,17 @@ import hashlib import sys import re +from ansible.errors import AnsibleError from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.connection import Connection -from ansible.plugins.action.network import ActionModule as NetworkActionModule +from ansible.plugins.action import ActionBase from ansible.module_utils.six.moves.urllib.parse import urlsplit from ansible.utils.display import Display display = Display() -class ActionModule(NetworkActionModule): +class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): changed = True @@ -195,3 +196,24 @@ class ActionModule(NetworkActionModule): raise ValueError('path specified in src not found') return source + + def _get_working_path(self): + cwd = self._loader.get_basedir() + if self._task._role is not None: + cwd = self._task._role._role_path + return cwd + + def _get_network_os(self, task_vars): + if 'network_os' in self._task.args and self._task.args['network_os']: + display.vvvv('Getting network OS from task argument') + network_os = self._task.args['network_os'] + elif self._play_context.network_os: + display.vvvv('Getting network OS from inventory') + network_os = self._play_context.network_os + elif 'network_os' in task_vars.get('ansible_facts', {}) and task_vars['ansible_facts']['network_os']: + display.vvvv('Getting network OS from fact') + network_os = task_vars['ansible_facts']['network_os'] + else: + raise AnsibleError('ansible_network_os must be specified on this host') + + return network_os