Skip to content

Commit

Permalink
Fix net_get and net_put task run failure (ansible#56145)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ganeshrn authored May 7, 2019
1 parent 0e0c2a7 commit 9271b4e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
28 changes: 25 additions & 3 deletions lib/ansible/plugins/action/net_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
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
Expand All @@ -48,7 +49,7 @@ def run(self, tmp=None, task_vars=None):
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}

Expand Down Expand Up @@ -152,3 +153,24 @@ def _handle_existing_file(self, conn, source, dest, proto, timeout):
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
26 changes: 24 additions & 2 deletions lib/ansible/plugins/action/net_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
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
Expand Down Expand Up @@ -195,3 +196,24 @@ def _get_binary_src_file(self, src):
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

0 comments on commit 9271b4e

Please sign in to comment.