mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Consolidate boolean/mk_boolean conversion functions into a single location
Consolidate the module_utils, constants, and config functions that convert values into booleans into a single function in module_utils. Port code to use the module_utils.validate.convert_bool.boolean function isntead of mk_boolean.
This commit is contained in:
@@ -25,9 +25,9 @@ import os.path
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_native, to_text
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.hashing import checksum_s
|
||||
|
||||
@@ -101,7 +101,7 @@ class ActionModule(ActionBase):
|
||||
result['msg'] = "src and dest are required"
|
||||
return result
|
||||
|
||||
if boolean(remote_src):
|
||||
if boolean(remote_src, strict=False):
|
||||
result.update(self._execute_module(tmp=tmp, task_vars=task_vars))
|
||||
return result
|
||||
else:
|
||||
|
||||
@@ -24,9 +24,9 @@ import os
|
||||
import stat
|
||||
import tempfile
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.errors import AnsibleError, AnsibleFileNotFound
|
||||
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.hashing import checksum
|
||||
|
||||
@@ -43,11 +43,11 @@ class ActionModule(ActionBase):
|
||||
source = self._task.args.get('src', None)
|
||||
content = self._task.args.get('content', None)
|
||||
dest = self._task.args.get('dest', None)
|
||||
raw = boolean(self._task.args.get('raw', 'no'))
|
||||
force = boolean(self._task.args.get('force', 'yes'))
|
||||
remote_src = boolean(self._task.args.get('remote_src', False))
|
||||
follow = boolean(self._task.args.get('follow', False))
|
||||
decrypt = boolean(self._task.args.get('decrypt', True))
|
||||
raw = boolean(self._task.args.get('raw', 'no'), strict=False)
|
||||
force = boolean(self._task.args.get('force', 'yes'), strict=False)
|
||||
remote_src = boolean(self._task.args.get('remote_src', False), strict=False)
|
||||
follow = boolean(self._task.args.get('follow', False), strict=False)
|
||||
decrypt = boolean(self._task.args.get('decrypt', True), strict=False)
|
||||
|
||||
result['failed'] = True
|
||||
if (source is None and content is None) or dest is None:
|
||||
|
||||
@@ -20,10 +20,10 @@ __metaclass__ = type
|
||||
import os
|
||||
import base64
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.hashing import checksum, checksum_s, md5, secure_hash
|
||||
from ansible.utils.path import makedirs_safe
|
||||
@@ -51,9 +51,11 @@ class ActionModule(ActionBase):
|
||||
|
||||
source = self._task.args.get('src', None)
|
||||
dest = self._task.args.get('dest', None)
|
||||
flat = boolean(self._task.args.get('flat'))
|
||||
fail_on_missing = boolean(self._task.args.get('fail_on_missing'))
|
||||
validate_checksum = boolean(self._task.args.get('validate_checksum', self._task.args.get('validate_md5', True)))
|
||||
flat = boolean(self._task.args.get('flat'), strict=False)
|
||||
fail_on_missing = boolean(self._task.args.get('fail_on_missing'), strict=False)
|
||||
validate_checksum = boolean(self._task.args.get('validate_checksum',
|
||||
self._task.args.get('validate_md5', True)),
|
||||
strict=False)
|
||||
|
||||
# validate source and dest are strings FIXME: use basic.py and module specs
|
||||
if not isinstance(source, string_types):
|
||||
|
||||
@@ -20,9 +20,9 @@ __metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class ActionModule(ActionBase):
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
src = self._task.args.get('src', None)
|
||||
remote_src = boolean(self._task.args.get('remote_src', 'no'))
|
||||
remote_src = boolean(self._task.args.get('remote_src', 'no'), strict=False)
|
||||
|
||||
if src is None:
|
||||
result['failed'] = True
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.vars import isidentifier
|
||||
|
||||
@@ -46,7 +46,7 @@ class ActionModule(ActionBase):
|
||||
return result
|
||||
|
||||
if isinstance(v, string_types) and v.lower() in ('true', 'false', 'yes', 'no'):
|
||||
v = boolean(v)
|
||||
v = boolean(v, strict=False)
|
||||
facts[k] = v
|
||||
|
||||
result['changed'] = False
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.vars import isidentifier
|
||||
|
||||
@@ -53,7 +53,7 @@ class ActionModule(ActionBase):
|
||||
val = self._task.args.get(opt, None)
|
||||
if val is not None:
|
||||
if not isinstance(val, bool):
|
||||
stats[opt] = boolean(self._templar.template(val))
|
||||
stats[opt] = boolean(self._templar.template(val), strict=False)
|
||||
else:
|
||||
stats[opt] = val
|
||||
|
||||
|
||||
@@ -23,12 +23,11 @@ from collections import MutableSequence
|
||||
from ansible import constants as C
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.playbook.play_context import MAGIC_VARIABLE_MAPPING
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.plugins import connection_loader
|
||||
|
||||
boolean = C.mk_boolean
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
@@ -314,7 +313,7 @@ class ActionModule(ActionBase):
|
||||
user = None
|
||||
if not dest_is_local:
|
||||
# Src and dest rsync "path" handling
|
||||
if boolean(_tmp_args.get('set_remote_user', 'yes')):
|
||||
if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False):
|
||||
if use_delegate:
|
||||
user = task_vars.get('ansible_delegated_vars', dict()).get('ansible_ssh_user', None)
|
||||
if not user:
|
||||
|
||||
@@ -22,12 +22,11 @@ import os
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError, AnsibleFileNotFound
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.template import generate_ansible_template_vars
|
||||
from ansible.utils.hashing import checksum_s
|
||||
|
||||
boolean = C.mk_boolean
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
@@ -58,7 +57,7 @@ class ActionModule(ActionBase):
|
||||
|
||||
source = self._task.args.get('src', None)
|
||||
dest = self._task.args.get('dest', None)
|
||||
force = boolean(self._task.args.get('force', True))
|
||||
force = boolean(self._task.args.get('force', True), strict=False)
|
||||
state = self._task.args.get('state', None)
|
||||
newline_sequence = self._task.args.get('newline_sequence', self.DEFAULT_NEWLINE_SEQUENCE)
|
||||
variable_start_string = self._task.args.get('variable_start_string', None)
|
||||
|
||||
@@ -21,10 +21,9 @@ __metaclass__ = type
|
||||
import os
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
@@ -40,7 +39,7 @@ class ActionModule(ActionBase):
|
||||
|
||||
source = self._task.args.get('src', None)
|
||||
dest = self._task.args.get('dest', None)
|
||||
remote_src = boolean(self._task.args.get('remote_src', False))
|
||||
remote_src = boolean(self._task.args.get('remote_src', False), strict=False)
|
||||
creates = self._task.args.get('creates', None)
|
||||
decrypt = self._task.args.get('decrypt', True)
|
||||
|
||||
@@ -53,7 +52,7 @@ class ActionModule(ActionBase):
|
||||
return result
|
||||
# We will take the information from copy and store it in
|
||||
# the remote_src var to use later in this file.
|
||||
self._task.args['remote_src'] = remote_src = not boolean(self._task.args.pop('copy'))
|
||||
self._task.args['remote_src'] = remote_src = not boolean(self._task.args.pop('copy'), strict=False)
|
||||
|
||||
if source is None or dest is None:
|
||||
result['failed'] = True
|
||||
@@ -79,17 +78,17 @@ class ActionModule(ActionBase):
|
||||
if not remote_src:
|
||||
try:
|
||||
source = self._loader.get_real_file(self._find_needle('files', source), decrypt=decrypt)
|
||||
except AnsibleError:
|
||||
except AnsibleError as e:
|
||||
result['failed'] = True
|
||||
result['msg'] = to_native(get_exception())
|
||||
result['msg'] = to_text(e)
|
||||
self._remove_tmp_path(tmp)
|
||||
return result
|
||||
|
||||
try:
|
||||
remote_stat = self._execute_remote_stat(dest, all_vars=task_vars, follow=True)
|
||||
except AnsibleError:
|
||||
except AnsibleError as e:
|
||||
result['failed'] = True
|
||||
result['msg'] = to_native(get_exception())
|
||||
result['msg'] = to_text(e)
|
||||
self._remove_tmp_path(tmp)
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user