|
|
|
@ -14,6 +14,7 @@ from ansible.module_utils.parsing.convert_bool import boolean, BOOLEANS_TRUE
|
|
|
|
|
from ansible.module_utils.six import string_types
|
|
|
|
|
from ansible.config.manager import ConfigManager, ensure_type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _deprecated(msg):
|
|
|
|
|
''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
|
|
|
|
|
try:
|
|
|
|
@ -23,11 +24,13 @@ def _deprecated(msg):
|
|
|
|
|
import sys
|
|
|
|
|
sys.stderr.write('[DEPRECATED] %s, to be removed in 2.8' % msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mk_boolean(value):
|
|
|
|
|
''' moved to module_utils'''
|
|
|
|
|
_deprecated('ansible.constants.mk_boolean() is deprecated. Use ansible.module_utils.parsing.convert_bool.boolean() instead')
|
|
|
|
|
return boolean(value, strict=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config(parser, section, key, env_var, default_value, value_type=None, expand_relative_paths=False):
|
|
|
|
|
''' kept for backwarsd compatibility, but deprecated '''
|
|
|
|
|
_deprecated('ansible.constants.get_config() is deprecated. There is new config API, see porting docs.')
|
|
|
|
@ -49,10 +52,12 @@ def get_config(parser, section, key, env_var, default_value, value_type=None, ex
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_constant(name, value, export=vars()):
|
|
|
|
|
''' sets constants and returns resolved options dict '''
|
|
|
|
|
export[name] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### CONSTANTS ### yes, actual ones
|
|
|
|
|
BLACKLIST_EXTS = ('.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt')
|
|
|
|
|
BECOME_METHODS = ['sudo', 'su', 'pbrun', 'pfexec', 'doas', 'dzdo', 'ksu', 'runas', 'pmrun']
|
|
|
|
@ -99,15 +104,16 @@ config = ConfigManager()
|
|
|
|
|
# Generate constants from config
|
|
|
|
|
for setting in config.data.get_settings():
|
|
|
|
|
|
|
|
|
|
value = None
|
|
|
|
|
if isinstance(setting.value, string_types) and (setting.value.startswith('eval(') and setting.value.endswith(')')):
|
|
|
|
|
value = setting.value
|
|
|
|
|
if setting.origin == 'default' and \
|
|
|
|
|
isinstance(setting.value, string_types) and \
|
|
|
|
|
(setting.value.startswith('eval(') and setting.value.endswith(')')):
|
|
|
|
|
try:
|
|
|
|
|
# FIXME: find better way to do in manager class and/or ensure types
|
|
|
|
|
eval_string = setting.value.replace('eval(', '', 1)[:-1]
|
|
|
|
|
value = ensure_type(eval(eval_string), setting.type) # FIXME: safe eval?
|
|
|
|
|
except:
|
|
|
|
|
value = setting.value
|
|
|
|
|
# FIXME: should we warn?
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
set_constant(setting.name, value or setting.value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|