moved from eval to templating + literal_eval
This commit is contained in:
parent
31e7d735a3
commit
f12c6e0946
3 changed files with 19 additions and 21 deletions
|
@ -723,7 +723,7 @@ DEFAULT_MODULE_COMPRESSION:
|
||||||
# - name: ansible_module_compression
|
# - name: ansible_module_compression
|
||||||
DEFAULT_MODULE_LANG:
|
DEFAULT_MODULE_LANG:
|
||||||
name: Target language environment
|
name: Target language environment
|
||||||
default: eval(os.getenv('LANG', 'en_US.UTF-8'))
|
default: "{{CONTROLER_LANG}}"
|
||||||
description: "Language locale setting to use for modules when they execute on the target, if empty it defaults to 'en_US.UTF-8'"
|
description: "Language locale setting to use for modules when they execute on the target, if empty it defaults to 'en_US.UTF-8'"
|
||||||
env: [{name: ANSIBLE_MODULE_LANG}]
|
env: [{name: ANSIBLE_MODULE_LANG}]
|
||||||
ini:
|
ini:
|
||||||
|
@ -1255,7 +1255,7 @@ INVENTORY_ENABLED:
|
||||||
type: list
|
type: list
|
||||||
INVENTORY_IGNORE_EXTS:
|
INVENTORY_IGNORE_EXTS:
|
||||||
name: Inventory ignore extensions
|
name: Inventory ignore extensions
|
||||||
default: eval(BLACKLIST_EXTS + ( '~', '.orig', '.ini', '.cfg', '.retry'))
|
default: "{{(BLACKLIST_EXTS + ( '~', '.orig', '.ini', '.cfg', '.retry'))}}"
|
||||||
description: List of extensions to ignore when using a directory as an inventory source
|
description: List of extensions to ignore when using a directory as an inventory source
|
||||||
env: [{name: ANSIBLE_INVENTORY_IGNORE}]
|
env: [{name: ANSIBLE_INVENTORY_IGNORE}]
|
||||||
ini:
|
ini:
|
||||||
|
|
|
@ -317,18 +317,9 @@ class ConfigManager(object):
|
||||||
if value is None:
|
if value is None:
|
||||||
value = defs[config].get('default')
|
value = defs[config].get('default')
|
||||||
origin = 'default'
|
origin = 'default'
|
||||||
# FIXME: moved eval to constants as this does not have access to previous vars
|
# skip typing as this is a temlated default that will be resolved later in constants, which has needed vars
|
||||||
if plugin_type is None and isinstance(value, string_types) and (value.startswith('eval(') and value.endswith(')')):
|
if plugin_type is None and isinstance(value, string_types) and (value.startswith('{{') and value.endswith('}}')):
|
||||||
return value, origin
|
return value, origin
|
||||||
#default_value = defs[config].get('default')
|
|
||||||
#if plugin_type is None and isinstance(default_value, string_types) and (default_value.startswith('eval(') and default_value.endswith(')')):
|
|
||||||
# try:
|
|
||||||
# eval_string = default_value.replace('eval(', '', 1)[:-1]
|
|
||||||
# value = eval(eval_string) # FIXME: safe eval?
|
|
||||||
# except:
|
|
||||||
# value = default_value
|
|
||||||
#else:
|
|
||||||
# value = default_value
|
|
||||||
|
|
||||||
# ensure correct type
|
# ensure correct type
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,6 +7,9 @@ from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import os # used to set lang and for backwards compat get_config
|
import os # used to set lang and for backwards compat get_config
|
||||||
|
|
||||||
|
from ast import literal_eval
|
||||||
|
from jinja2 import Template
|
||||||
from string import ascii_letters, digits
|
from string import ascii_letters, digits
|
||||||
|
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
|
@ -57,7 +60,6 @@ def set_constant(name, value, export=vars()):
|
||||||
|
|
||||||
|
|
||||||
### CONSTANTS ### yes, actual ones
|
### CONSTANTS ### yes, actual ones
|
||||||
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']
|
||||||
BECOME_ERROR_STRINGS = {
|
BECOME_ERROR_STRINGS = {
|
||||||
'sudo': 'Sorry, try again.',
|
'sudo': 'Sorry, try again.',
|
||||||
|
@ -79,7 +81,9 @@ BECOME_MISSING_STRINGS = {
|
||||||
'ksu': 'No password given',
|
'ksu': 'No password given',
|
||||||
'pmrun': ''
|
'pmrun': ''
|
||||||
} # FIXME: deal with i18n
|
} # FIXME: deal with i18n
|
||||||
|
BLACKLIST_EXTS = ('.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt')
|
||||||
BOOL_TRUE = BOOLEANS_TRUE
|
BOOL_TRUE = BOOLEANS_TRUE
|
||||||
|
CONTROLER_LANG = os.getenv('LANG', 'en_US.UTF-8')
|
||||||
DEFAULT_BECOME_PASS = None
|
DEFAULT_BECOME_PASS = None
|
||||||
DEFAULT_PASSWORD_CHARS = to_text(ascii_letters + digits + ".,:-_", errors='strict') # characters included in auto-generated passwords
|
DEFAULT_PASSWORD_CHARS = to_text(ascii_letters + digits + ".,:-_", errors='strict') # characters included in auto-generated passwords
|
||||||
DEFAULT_SUDO_PASS = None
|
DEFAULT_SUDO_PASS = None
|
||||||
|
@ -105,13 +109,16 @@ for setting in config.data.get_settings():
|
||||||
value = setting.value
|
value = setting.value
|
||||||
if setting.origin == 'default' and \
|
if setting.origin == 'default' and \
|
||||||
isinstance(setting.value, string_types) and \
|
isinstance(setting.value, string_types) and \
|
||||||
(setting.value.startswith('eval(') and setting.value.endswith(')')):
|
(setting.value.startswith('{{') and setting.value.endswith('}}')):
|
||||||
try:
|
try:
|
||||||
# FIXME: find better way to do in manager class and/or ensure types
|
t = Template(setting.value)
|
||||||
eval_string = setting.value.replace('eval(', '', 1)[:-1]
|
value = t.render(vars())
|
||||||
value = ensure_type(eval(eval_string), setting.type) # FIXME: safe eval?
|
try:
|
||||||
|
value = literal_eval(value)
|
||||||
|
except ValueError:
|
||||||
|
pass # not a python data structure
|
||||||
except:
|
except:
|
||||||
# FIXME: should we warn?
|
pass # not templatable
|
||||||
pass
|
value = ensure_type(value, setting.name)
|
||||||
|
|
||||||
set_constant(setting.name, value or setting.value)
|
set_constant(setting.name, value)
|
||||||
|
|
Loading…
Reference in a new issue