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