* 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 <sjaiswal@redhat.com>
... | ... |
@@ -23,16 +23,17 @@ import re |
23 | 23 |
import uuid |
24 | 24 |
import hashlib |
25 | 25 |
|
26 |
+from ansible.errors import AnsibleError |
|
26 | 27 |
from ansible.module_utils._text import to_text, to_bytes |
27 | 28 |
from ansible.module_utils.connection import Connection |
28 |
-from ansible.plugins.action.network import ActionModule as NetworkActionModule |
|
29 |
+from ansible.plugins.action import ActionBase |
|
29 | 30 |
from ansible.module_utils.six.moves.urllib.parse import urlsplit |
30 | 31 |
from ansible.utils.display import Display |
31 | 32 |
|
32 | 33 |
display = Display() |
33 | 34 |
|
34 | 35 |
|
35 |
-class ActionModule(NetworkActionModule): |
|
36 |
+class ActionModule(ActionBase): |
|
36 | 37 |
|
37 | 38 |
def run(self, tmp=None, task_vars=None): |
38 | 39 |
socket_path = None |
... | ... |
@@ -48,7 +49,7 @@ class ActionModule(NetworkActionModule): |
48 | 48 |
return result |
49 | 49 |
|
50 | 50 |
try: |
51 |
- src = self._task.args.get('src') |
|
51 |
+ src = self._task.args['src'] |
|
52 | 52 |
except KeyError as exc: |
53 | 53 |
return {'failed': True, 'msg': 'missing required argument: %s' % exc} |
54 | 54 |
|
... | ... |
@@ -152,3 +153,24 @@ class ActionModule(NetworkActionModule): |
152 | 152 |
return False |
153 | 153 |
else: |
154 | 154 |
return True |
155 |
+ |
|
156 |
+ def _get_working_path(self): |
|
157 |
+ cwd = self._loader.get_basedir() |
|
158 |
+ if self._task._role is not None: |
|
159 |
+ cwd = self._task._role._role_path |
|
160 |
+ return cwd |
|
161 |
+ |
|
162 |
+ def _get_network_os(self, task_vars): |
|
163 |
+ if 'network_os' in self._task.args and self._task.args['network_os']: |
|
164 |
+ display.vvvv('Getting network OS from task argument') |
|
165 |
+ network_os = self._task.args['network_os'] |
|
166 |
+ elif self._play_context.network_os: |
|
167 |
+ display.vvvv('Getting network OS from inventory') |
|
168 |
+ network_os = self._play_context.network_os |
|
169 |
+ elif 'network_os' in task_vars.get('ansible_facts', {}) and task_vars['ansible_facts']['network_os']: |
|
170 |
+ display.vvvv('Getting network OS from fact') |
|
171 |
+ network_os = task_vars['ansible_facts']['network_os'] |
|
172 |
+ else: |
|
173 |
+ raise AnsibleError('ansible_network_os must be specified on this host') |
|
174 |
+ |
|
175 |
+ return network_os |
... | ... |
@@ -25,16 +25,17 @@ import hashlib |
25 | 25 |
import sys |
26 | 26 |
import re |
27 | 27 |
|
28 |
+from ansible.errors import AnsibleError |
|
28 | 29 |
from ansible.module_utils._text import to_text, to_bytes |
29 | 30 |
from ansible.module_utils.connection import Connection |
30 |
-from ansible.plugins.action.network import ActionModule as NetworkActionModule |
|
31 |
+from ansible.plugins.action import ActionBase |
|
31 | 32 |
from ansible.module_utils.six.moves.urllib.parse import urlsplit |
32 | 33 |
from ansible.utils.display import Display |
33 | 34 |
|
34 | 35 |
display = Display() |
35 | 36 |
|
36 | 37 |
|
37 |
-class ActionModule(NetworkActionModule): |
|
38 |
+class ActionModule(ActionBase): |
|
38 | 39 |
|
39 | 40 |
def run(self, tmp=None, task_vars=None): |
40 | 41 |
changed = True |
... | ... |
@@ -195,3 +196,24 @@ class ActionModule(NetworkActionModule): |
195 | 195 |
raise ValueError('path specified in src not found') |
196 | 196 |
|
197 | 197 |
return source |
198 |
+ |
|
199 |
+ def _get_working_path(self): |
|
200 |
+ cwd = self._loader.get_basedir() |
|
201 |
+ if self._task._role is not None: |
|
202 |
+ cwd = self._task._role._role_path |
|
203 |
+ return cwd |
|
204 |
+ |
|
205 |
+ def _get_network_os(self, task_vars): |
|
206 |
+ if 'network_os' in self._task.args and self._task.args['network_os']: |
|
207 |
+ display.vvvv('Getting network OS from task argument') |
|
208 |
+ network_os = self._task.args['network_os'] |
|
209 |
+ elif self._play_context.network_os: |
|
210 |
+ display.vvvv('Getting network OS from inventory') |
|
211 |
+ network_os = self._play_context.network_os |
|
212 |
+ elif 'network_os' in task_vars.get('ansible_facts', {}) and task_vars['ansible_facts']['network_os']: |
|
213 |
+ display.vvvv('Getting network OS from fact') |
|
214 |
+ network_os = task_vars['ansible_facts']['network_os'] |
|
215 |
+ else: |
|
216 |
+ raise AnsibleError('ansible_network_os must be specified on this host') |
|
217 |
+ |
|
218 |
+ return network_os |