diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 97f2202dd8f..d2297707282 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -32,15 +32,13 @@ from ansible.utils.path import makedirs_safe BOOL_TRUE = frozenset([ "true", "t", "y", "1", "yes", "on" ]) -# copied from utils, avoid circular reference fun :) def mk_boolean(value): - if value is None: - return False - val = str(value) - if val.lower() in BOOL_TRUE: - return True - else: - return False + ret = value + if not isinstance(value, bool): + if value is None: + ret = False + ret = (str(value).lower() in BOOL_TRUE) + return ret def shell_expand(path, expand_relative_paths=False): ''' diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index 078788d5287..625d2b9c6e7 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -22,15 +22,13 @@ __metaclass__ = type import fnmatch from ansible.compat.six import iteritems - from ansible import constants as C - from ansible.errors import AnsibleError from ansible.playbook.block import Block from ansible.playbook.task import Task from ansible.playbook.role_include import IncludeRole -from ansible.utils.boolean import boolean +boolean = C.mk_boolean __all__ = ['PlayIterator'] diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 11f908d1816..41a437c22d7 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -33,7 +33,7 @@ from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable from ansible.module_utils._text import to_text from ansible.playbook.attribute import Attribute, FieldAttribute from ansible.parsing.dataloader import DataLoader -from ansible.utils.boolean import boolean +from ansible.constants import mk_boolean as boolean from ansible.utils.vars import combine_vars, isidentifier try: diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 1eac6f05bf1..b04cb7f0561 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -34,7 +34,8 @@ from ansible.errors import AnsibleError from ansible.module_utils._text import to_bytes from ansible.playbook.attribute import FieldAttribute from ansible.playbook.base import Base -from ansible.utils.boolean import boolean + +boolean = C.mk_boolean __all__ = ['PlayContext'] diff --git a/lib/ansible/plugins/action/assemble.py b/lib/ansible/plugins/action/assemble.py index ef7e337150c..3a3f0fc29f6 100644 --- a/lib/ansible/plugins/action/assemble.py +++ b/lib/ansible/plugins/action/assemble.py @@ -25,10 +25,10 @@ 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.plugins.action import ActionBase -from ansible.utils.boolean import boolean from ansible.utils.hashing import checksum_s diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py index 41290c8f9e6..fe300b23e4c 100644 --- a/lib/ansible/plugins/action/copy.py +++ b/lib/ansible/plugins/action/copy.py @@ -24,10 +24,10 @@ import os import stat import tempfile +from ansible.constants import mk_boolean as boolean from ansible.errors import AnsibleError from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.plugins.action import ActionBase -from ansible.utils.boolean import boolean from ansible.utils.hashing import checksum diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py index 2d32744294e..03cf553474f 100644 --- a/lib/ansible/plugins/action/fetch.py +++ b/lib/ansible/plugins/action/fetch.py @@ -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.plugins.action import ActionBase -from ansible.utils.boolean import boolean from ansible.utils.hashing import checksum, checksum_s, md5, secure_hash from ansible.utils.path import makedirs_safe diff --git a/lib/ansible/plugins/action/patch.py b/lib/ansible/plugins/action/patch.py index 94bcf677467..88fe91ec2c2 100644 --- a/lib/ansible/plugins/action/patch.py +++ b/lib/ansible/plugins/action/patch.py @@ -20,10 +20,10 @@ __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.plugins.action import ActionBase -from ansible.utils.boolean import boolean class ActionModule(ActionBase): diff --git a/lib/ansible/plugins/action/set_fact.py b/lib/ansible/plugins/action/set_fact.py index 7acc48c781e..b16927b3f2a 100644 --- a/lib/ansible/plugins/action/set_fact.py +++ b/lib/ansible/plugins/action/set_fact.py @@ -20,8 +20,8 @@ __metaclass__ = type from ansible.compat.six import iteritems, string_types +from ansible.constants import mk_boolean as boolean from ansible.plugins.action import ActionBase -from ansible.utils.boolean import boolean from ansible.utils.vars import isidentifier class ActionModule(ActionBase): diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index 0087b588576..4b13f3990d4 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -22,9 +22,10 @@ import os.path from ansible.playbook.play_context import MAGIC_VARIABLE_MAPPING from ansible.plugins.action import ActionBase from ansible.plugins import connection_loader -from ansible.utils.boolean import boolean from ansible import constants as C +boolean = C.mk_boolean + class ActionModule(ActionBase): diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py index 34f452f7a3b..43dc6922edd 100644 --- a/lib/ansible/plugins/action/template.py +++ b/lib/ansible/plugins/action/template.py @@ -27,8 +27,8 @@ from ansible.errors import AnsibleError from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.plugins.action import ActionBase from ansible.utils.hashing import checksum_s -from ansible.utils.boolean import boolean +boolean = C.mk_boolean class ActionModule(ActionBase): diff --git a/lib/ansible/plugins/action/unarchive.py b/lib/ansible/plugins/action/unarchive.py index 3966984d62c..818d7d884c6 100644 --- a/lib/ansible/plugins/action/unarchive.py +++ b/lib/ansible/plugins/action/unarchive.py @@ -23,7 +23,7 @@ import os from ansible.errors import AnsibleError from ansible.module_utils._text import to_native from ansible.plugins.action import ActionBase -from ansible.utils.boolean import boolean +from ansible.constants import mk_boolean as boolean class ActionModule(ActionBase): diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 36b3e2610bf..b4ed0398d18 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -35,9 +35,9 @@ from ansible.errors import AnsibleOptionsError from ansible.module_utils.basic import BOOLEANS from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.plugins.connection import ConnectionBase -from ansible.utils.boolean import boolean from ansible.utils.path import unfrackpath, makedirs_safe +boolean = C.mk_boolean try: from __main__ import display diff --git a/lib/ansible/plugins/lookup/first_found.py b/lib/ansible/plugins/lookup/first_found.py index 43fc3a7a77c..36e86188d13 100644 --- a/lib/ansible/plugins/lookup/first_found.py +++ b/lib/ansible/plugins/lookup/first_found.py @@ -125,7 +125,7 @@ from jinja2.exceptions import UndefinedError from ansible.compat.six import string_types from ansible.errors import AnsibleFileNotFound, AnsibleLookupError, AnsibleUndefinedVariable from ansible.plugins.lookup import LookupBase -from ansible.utils.boolean import boolean +from ansible.constants import mk_boolean as boolean class LookupModule(LookupBase): diff --git a/lib/ansible/plugins/lookup/subelements.py b/lib/ansible/plugins/lookup/subelements.py index 214a03a8f4e..8e8c16b8852 100644 --- a/lib/ansible/plugins/lookup/subelements.py +++ b/lib/ansible/plugins/lookup/subelements.py @@ -21,7 +21,7 @@ from ansible.compat.six import string_types from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase from ansible.utils.listify import listify_lookup_plugin_terms -from ansible.utils.boolean import boolean +from ansible.constants import mk_boolean as boolean FLAGS = ('skip_missing',) diff --git a/lib/ansible/utils/boolean.py b/lib/ansible/utils/boolean.py deleted file mode 100644 index bf15be346d0..00000000000 --- a/lib/ansible/utils/boolean.py +++ /dev/null @@ -1,29 +0,0 @@ -# (c) 2012-2014, Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - - -def boolean(value): - val = str(value) - if val.lower() in [ "true", "t", "y", "1", "yes" ]: - return True - else: - return False - diff --git a/test/integration/group_vars/all b/test/integration/group_vars/all index df4be050cfd..0f8a2260309 100644 --- a/test/integration/group_vars/all +++ b/test/integration/group_vars/all @@ -13,5 +13,5 @@ test_hash: # variables used for conditional testing test_bare: true test_bare_var: 123 -test_bare_nested_good: "{{test_bare_var}} == 123" +test_bare_nested_good: "test_bare_var == 123" test_bare_nested_bad: "{{test_bare_var}} == 321"