mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +00:00
fixup use validate_argument_spec, remove imports
This commit is contained in:
parent
fa795788cd
commit
e6ee55be8f
1 changed files with 11 additions and 28 deletions
|
|
@ -4,16 +4,10 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from ansible import constants as C
|
|
||||||
|
|
||||||
from ansible.config.manager import ensure_type
|
|
||||||
from ansible.errors import AnsibleActionFail, AnsibleError
|
from ansible.errors import AnsibleActionFail, AnsibleError
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_text, to_native
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
|
||||||
from ansible.plugins.action import ActionBase
|
from ansible.plugins.action import ActionBase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -37,33 +31,22 @@ class ActionModule(ActionBase):
|
||||||
if task_vars is None:
|
if task_vars is None:
|
||||||
task_vars = dict()
|
task_vars = dict()
|
||||||
|
|
||||||
|
validation_result, new_module_args = self.validate_argument_spec(
|
||||||
|
argument_spec = {'src': {'required': True, 'type': 'str'},
|
||||||
|
'dest': {'required': True, 'type': 'str'},
|
||||||
|
'follow': {'type': 'bool', 'default': False}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
super(ActionModule, self).run(tmp, task_vars)
|
super(ActionModule, self).run(tmp, task_vars)
|
||||||
del tmp # tmp no longer has any effect
|
del tmp # tmp no longer has any effect
|
||||||
|
|
||||||
# Options type validation
|
|
||||||
# strings
|
|
||||||
for s_type in ('src', 'dest'):
|
|
||||||
if s_type in self._task.args:
|
|
||||||
value = ensure_type(self._task.args[s_type], 'string')
|
|
||||||
if value is not None and not isinstance(value, str):
|
|
||||||
raise AnsibleActionFail("%s is expected to be a string, but got %s instead" % (s_type, type(value)))
|
|
||||||
self._task.args[s_type] = value
|
|
||||||
|
|
||||||
# booleans
|
|
||||||
try:
|
|
||||||
follow = boolean(self._task.args.get('follow', False), strict=False)
|
|
||||||
except TypeError as e:
|
|
||||||
raise AnsibleActionFail(to_native(e))
|
|
||||||
|
|
||||||
# assign to local vars for ease of use
|
# assign to local vars for ease of use
|
||||||
source = self._task.args.get('src', None)
|
source = new_module_args['src']
|
||||||
dest = self._task.args.get('dest', None)
|
dest = new_module_args['dest']
|
||||||
|
follow = new_module_args['follow']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# logical validation
|
|
||||||
if source is None or dest is None:
|
|
||||||
raise AnsibleActionFail("src and dest are required")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# find in expected paths
|
# find in expected paths
|
||||||
source = self._find_needle('files', source)
|
source = self._find_needle('files', source)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue