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 9271b4e368
)
* backport changelog
Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>
This commit is contained in:
parent
72af010414
commit
387093a0d6
3 changed files with 51 additions and 5 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Fix net_get and net_put task run failure - https://github.com/ansible/ansible/pull/56145
|
|
@ -23,16 +23,17 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils._text import to_text, to_bytes
|
from ansible.module_utils._text import to_text, to_bytes
|
||||||
from ansible.module_utils.connection import Connection
|
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.module_utils.six.moves.urllib.parse import urlsplit
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(NetworkActionModule):
|
class ActionModule(ActionBase):
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
socket_path = None
|
socket_path = None
|
||||||
|
@ -48,7 +49,7 @@ class ActionModule(NetworkActionModule):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
src = self._task.args.get('src')
|
src = self._task.args['src']
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
return {'failed': True, 'msg': 'missing required argument: %s' % exc}
|
return {'failed': True, 'msg': 'missing required argument: %s' % exc}
|
||||||
|
|
||||||
|
@ -152,3 +153,24 @@ class ActionModule(NetworkActionModule):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
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
|
||||||
|
|
|
@ -25,16 +25,17 @@ import hashlib
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils._text import to_text, to_bytes
|
from ansible.module_utils._text import to_text, to_bytes
|
||||||
from ansible.module_utils.connection import Connection
|
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.module_utils.six.moves.urllib.parse import urlsplit
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(NetworkActionModule):
|
class ActionModule(ActionBase):
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -195,3 +196,24 @@ class ActionModule(NetworkActionModule):
|
||||||
raise ValueError('path specified in src not found')
|
raise ValueError('path specified in src not found')
|
||||||
|
|
||||||
return source
|
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
|
||||||
|
|
Loading…
Reference in a new issue