5from __future__
import (absolute_import, division, print_function)
11from ast
import literal_eval
12from jinja2
import Template
13from string
import ascii_letters, digits
24 ''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
30 sys.stderr.write(
' [WARNING] %s\n' % (msg))
34 ''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
37 Display().deprecated(msg, version=version)
40 sys.stderr.write(
' [DEPRECATED] %s, to be removed in %s\n' % (msg, version))
44 ''' moved to module_utils'''
45 _deprecated(
'ansible.constants.mk_boolean() is deprecated. Use ansible.module_utils.parsing.convert_bool.boolean() instead')
46 return boolean(value, strict=
False)
49def get_config(parser, section, key, env_var, default_value, value_type=None, expand_relative_paths=False):
50 ''' kept for backwarsd compatibility, but deprecated '''
51 _deprecated(
'ansible.constants.get_config() is deprecated. There is new config API, see porting docs.')
55 value = os.environ.get(env_var,
None)
70 ''' sets constants and returns resolved options dict '''
82 return len(self.
_value_value)
86 return self.
_value_value[y]
91 [
'sudo',
'su',
'pbrun',
'pfexec',
'doas',
'dzdo',
'ksu',
'runas',
'pmrun',
'enable',
'machinectl'],
92 (
'ansible.constants.BECOME_METHODS is deprecated, please use '
93 'ansible.plugins.loader.become_loader. This list is statically '
94 'defined and may not include all become methods'),
99BLACKLIST_EXTS = (
'.pyc',
'.pyo',
'.swp',
'.bak',
'~',
'.rpm',
'.md',
'.txt',
'.rst')
100BOOL_TRUE = BOOLEANS_TRUE
101DEFAULT_BECOME_PASS =
None
102DEFAULT_PASSWORD_CHARS =
to_text(ascii_letters + digits +
".,:-_", errors=
'strict')
103DEFAULT_REMOTE_PASS =
None
106CONFIGURABLE_PLUGINS = (
'become',
'cache',
'callback',
'cliconf',
'connection',
'httpapi',
'inventory',
'lookup',
'netconf',
'shell')
108DOCUMENTABLE_PLUGINS = CONFIGURABLE_PLUGINS + (
'module',
'strategy',
'vars')
109IGNORE_FILES = (
"COPYING",
"CONTRIBUTING",
"LICENSE",
"README",
"VERSION",
"GUIDELINES")
110INTERNAL_RESULT_KEYS = (
'add_host',
'add_group')
111LOCALHOST = (
'127.0.0.1',
'localhost',
'::1')
112MODULE_REQUIRE_ARGS = tuple(
add_internal_fqcns((
'command',
'win_command',
'shell',
'win_shell',
'raw',
'script')))
114RESTRICTED_RESULT_KEYS = (
'ansible_rsync_path',
'ansible_playbook_python',
'ansible_facts')
116VAULT_VERSION_MIN = 1.0
117VAULT_VERSION_MAX = 1.0
120INVALID_VARIABLE_NAMES = re.compile(
r'^[\d\W]|[^\w]')
129COMMON_CONNECTION_VARS = frozenset((
'ansible_connection',
'ansible_host',
'ansible_user',
'ansible_shell_executable',
130 'ansible_port',
'ansible_pipelining',
'ansible_password',
'ansible_timeout',
131 'ansible_shell_type',
'ansible_module_compression',
'ansible_private_key_file'))
133MAGIC_VARIABLE_MAPPING = dict(
136 connection=(
'ansible_connection', ),
137 module_compression=(
'ansible_module_compression', ),
138 shell=(
'ansible_shell_type', ),
139 executable=(
'ansible_shell_executable', ),
142 remote_addr=(
'ansible_ssh_host',
'ansible_host'),
143 remote_user=(
'ansible_ssh_user',
'ansible_user'),
144 password=(
'ansible_ssh_pass',
'ansible_password'),
145 port=(
'ansible_ssh_port',
'ansible_port'),
146 pipelining=(
'ansible_ssh_pipelining',
'ansible_pipelining'),
147 timeout=(
'ansible_ssh_timeout',
'ansible_timeout'),
148 private_key_file=(
'ansible_ssh_private_key_file',
'ansible_private_key_file'),
151 network_os=(
'ansible_network_os', ),
152 connection_user=(
'ansible_connection_user',),
155 ssh_executable=(
'ansible_ssh_executable', ),
156 ssh_common_args=(
'ansible_ssh_common_args', ),
157 sftp_extra_args=(
'ansible_sftp_extra_args', ),
158 scp_extra_args=(
'ansible_scp_extra_args', ),
159 ssh_extra_args=(
'ansible_ssh_extra_args', ),
160 ssh_transfer_method=(
'ansible_ssh_transfer_method', ),
163 docker_extra_args=(
'ansible_docker_extra_args', ),
166 become=(
'ansible_become', ),
167 become_method=(
'ansible_become_method', ),
168 become_user=(
'ansible_become_user', ),
169 become_pass=(
'ansible_become_password',
'ansible_become_pass'),
170 become_exe=(
'ansible_become_exe', ),
171 become_flags=(
'ansible_become_flags', ),
178for setting
in config.data.get_settings():
180 value = setting.value
181 if setting.origin ==
'default' and \
182 isinstance(setting.value, string_types)
and \
183 (setting.value.startswith(
'{{')
and setting.value.endswith(
'}}')):
185 t = Template(setting.value)
186 value = t.render(vars())
198for warn
in config.WARNINGS:
216_ACTION_ALL_INCLUDES = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_INCLUDE_ROLE
217_ACTION_ALL_IMPORT_PLAYBOOKS = _ACTION_INCLUDE + _ACTION_IMPORT_PLAYBOOK
218_ACTION_ALL_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS
219_ACTION_ALL_PROPER_INCLUDE_IMPORT_ROLES = _ACTION_INCLUDE_ROLE + _ACTION_IMPORT_ROLE
220_ACTION_ALL_PROPER_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS
221_ACTION_ALL_INCLUDE_ROLE_TASKS = _ACTION_INCLUDE_ROLE + _ACTION_INCLUDE_TASKS
222_ACTION_ALL_INCLUDE_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS
224_ACTION_WITH_CLEAN_FACTS = _ACTION_SET_FACT + _ACTION_INCLUDE_VARS
def __init__(self, value, msg, version)
def get_ini_config_value(p, entry)
def ensure_type(value, value_type, origin=None)
def get_config(parser, section, key, env_var, default_value, value_type=None, expand_relative_paths=False)
def _deprecated(msg, version='2.8')
def set_constant(name, value, export=vars())
def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr')
def boolean(value, strict=True)
def literal_eval(node_or_string)
def add_internal_fqcns(names)