mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
c9e05956b7
commit
ac1017b7ad
2 changed files with 176 additions and 177 deletions
|
@ -30,7 +30,8 @@ from ansible.module_utils._text import to_text
|
|||
from ansible.parsing.quoting import unquote
|
||||
from ansible.utils.path import makedirs_safe
|
||||
|
||||
BOOL_TRUE = frozenset([ "true", "t", "y", "1", "yes", "on" ])
|
||||
BOOL_TRUE = frozenset(["true", "t", "y", "1", "yes", "on"])
|
||||
|
||||
|
||||
def mk_boolean(value):
|
||||
ret = value
|
||||
|
@ -40,6 +41,7 @@ def mk_boolean(value):
|
|||
ret = (str(value).lower() in BOOL_TRUE)
|
||||
return ret
|
||||
|
||||
|
||||
def shell_expand(path, expand_relative_paths=False):
|
||||
'''
|
||||
shell_expand is needed as os.path.expanduser does not work
|
||||
|
@ -55,6 +57,7 @@ def shell_expand(path, expand_relative_paths=False):
|
|||
path = os.path.abspath(path)
|
||||
return path
|
||||
|
||||
|
||||
def get_config(p, section, key, env_var, default, value_type=None, expand_relative_paths=False):
|
||||
''' return a configuration variable with casting
|
||||
|
||||
|
@ -112,8 +115,7 @@ def get_config(p, section, key, env_var, default, value_type=None, expand_relati
|
|||
|
||||
elif value_type == 'pathlist':
|
||||
if isinstance(value, string_types):
|
||||
value = [shell_expand(x, expand_relative_paths=expand_relative_paths) \
|
||||
for x in value.split(os.pathsep)]
|
||||
value = [shell_expand(x, expand_relative_paths=expand_relative_paths) for x in value.split(os.pathsep)]
|
||||
|
||||
elif isinstance(value, string_types):
|
||||
value = unquote(value)
|
||||
|
@ -170,32 +172,31 @@ p, CONFIG_FILE = load_config_file()
|
|||
|
||||
# check all of these extensions when looking for yaml files for things like
|
||||
# group variables -- really anything we can load
|
||||
YAML_FILENAME_EXTENSIONS = [ "", ".yml", ".yaml", ".json" ]
|
||||
YAML_FILENAME_EXTENSIONS = ["", ".yml", ".yaml", ".json"]
|
||||
|
||||
# the default whitelist for cow stencils
|
||||
DEFAULT_COW_WHITELIST = ['bud-frogs', 'bunny', 'cheese', 'daemon', 'default', 'dragon', 'elephant-in-snake', 'elephant',
|
||||
'eyes', 'hellokitty', 'kitty', 'luke-koala', 'meow', 'milk', 'moofasa', 'moose', 'ren', 'sheep',
|
||||
'small', 'stegosaurus', 'stimpy', 'supermilker', 'three-eyes', 'turkey', 'turtle', 'tux', 'udder',
|
||||
'vader-koala', 'vader', 'www',]
|
||||
'vader-koala', 'vader', 'www']
|
||||
|
||||
# sections in config file
|
||||
DEFAULTS='defaults'
|
||||
DEFAULTS = 'defaults'
|
||||
|
||||
|
||||
# FIXME: add deprecation warning when these get set
|
||||
#### DEPRECATED VARS ####
|
||||
#
|
||||
# DEPRECATED VARS
|
||||
|
||||
#### If --tags or --skip-tags is given multiple times on the CLI and this is
|
||||
# If --tags or --skip-tags is given multiple times on the CLI and this is
|
||||
# True, merge the lists of tags together. If False, let the last argument
|
||||
# overwrite any previous ones. Behaviour is overwrite through 2.2. 2.3
|
||||
# overwrites but prints deprecation. 2.4 the default is to merge.
|
||||
MERGE_MULTIPLE_CLI_TAGS = get_config(p, DEFAULTS, 'merge_multiple_cli_tags', 'ANSIBLE_MERGE_MULTIPLE_CLI_TAGS', True, value_type='boolean')
|
||||
|
||||
#### GENERALLY CONFIGURABLE THINGS ####
|
||||
# GENERALLY CONFIGURABLE THINGS
|
||||
DEFAULT_DEBUG = get_config(p, DEFAULTS, 'debug', 'ANSIBLE_DEBUG', False, value_type='boolean')
|
||||
DEFAULT_VERBOSITY = get_config(p, DEFAULTS, 'verbosity', 'ANSIBLE_VERBOSITY', 0, value_type='integer')
|
||||
DEFAULT_HOST_LIST = get_config(p, DEFAULTS,'inventory', 'ANSIBLE_INVENTORY', '/etc/ansible/hosts', value_type='path')
|
||||
DEFAULT_HOST_LIST = get_config(p, DEFAULTS, 'inventory', 'ANSIBLE_INVENTORY', '/etc/ansible/hosts', value_type='path')
|
||||
DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH',
|
||||
'~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles',
|
||||
value_type='pathlist', expand_relative_paths=True)
|
||||
|
@ -206,8 +207,8 @@ DEFAULT_FACT_PATH = get_config(p, DEFAULTS, 'fact_path', 'ANSIBLE
|
|||
DEFAULT_FORKS = get_config(p, DEFAULTS, 'forks', 'ANSIBLE_FORKS', 5, value_type='integer')
|
||||
DEFAULT_MODULE_ARGS = get_config(p, DEFAULTS, 'module_args', 'ANSIBLE_MODULE_ARGS', '')
|
||||
DEFAULT_MODULE_LANG = get_config(p, DEFAULTS, 'module_lang', 'ANSIBLE_MODULE_LANG', os.getenv('LANG', 'en_US.UTF-8'))
|
||||
DEFAULT_MODULE_SET_LOCALE = get_config(p, DEFAULTS, 'module_set_locale','ANSIBLE_MODULE_SET_LOCALE',False, value_type='boolean')
|
||||
DEFAULT_MODULE_COMPRESSION= get_config(p, DEFAULTS, 'module_compression', None, 'ZIP_DEFLATED')
|
||||
DEFAULT_MODULE_SET_LOCALE = get_config(p, DEFAULTS, 'module_set_locale', 'ANSIBLE_MODULE_SET_LOCALE', False, value_type='boolean')
|
||||
DEFAULT_MODULE_COMPRESSION = get_config(p, DEFAULTS, 'module_compression', None, 'ZIP_DEFLATED')
|
||||
DEFAULT_TIMEOUT = get_config(p, DEFAULTS, 'timeout', 'ANSIBLE_TIMEOUT', 10, value_type='integer')
|
||||
DEFAULT_POLL_INTERVAL = get_config(p, DEFAULTS, 'poll_interval', 'ANSIBLE_POLL_INTERVAL', 15, value_type='integer')
|
||||
DEFAULT_REMOTE_USER = get_config(p, DEFAULTS, 'remote_user', 'ANSIBLE_REMOTE_USER', None)
|
||||
|
@ -254,7 +255,7 @@ ALLOW_WORLD_READABLE_TMPFILES = get_config(p, DEFAULTS, 'allow_world_readable_tm
|
|||
DEFAULT_SELINUX_SPECIAL_FS = get_config(p, 'selinux', 'special_context_filesystems', None, 'fuse, nfs, vboxsf, ramfs, 9p', value_type='list')
|
||||
DEFAULT_LIBVIRT_LXC_NOSECLABEL = get_config(p, 'selinux', 'libvirt_lxc_noseclabel', 'LIBVIRT_LXC_NOSECLABEL', False, value_type='boolean')
|
||||
|
||||
### PRIVILEGE ESCALATION ###
|
||||
# PRIVILEGE ESCALATION
|
||||
# Backwards Compat
|
||||
DEFAULT_SU = get_config(p, DEFAULTS, 'su', 'ANSIBLE_SU', False, value_type='boolean')
|
||||
DEFAULT_SU_USER = get_config(p, DEFAULTS, 'su_user', 'ANSIBLE_SU_USER', 'root')
|
||||
|
@ -286,11 +287,11 @@ BECOME_MISSING_STRINGS = {
|
|||
'dzdo': '',
|
||||
'ksu': 'No password given'
|
||||
} # FIXME: deal with i18n
|
||||
BECOME_METHODS = ['sudo','su','pbrun','pfexec','doas','dzdo','ksu','runas']
|
||||
BECOME_METHODS = ['sudo', 'su', 'pbrun', 'pfexec', 'doas', 'dzdo', 'ksu', 'runas']
|
||||
BECOME_ALLOW_SAME_USER = get_config(p, 'privilege_escalation', 'become_allow_same_user', 'ANSIBLE_BECOME_ALLOW_SAME_USER', False, value_type='boolean')
|
||||
DEFAULT_BECOME_METHOD = get_config(p, 'privilege_escalation', 'become_method', 'ANSIBLE_BECOME_METHOD',
|
||||
'sudo' if DEFAULT_SUDO else 'su' if DEFAULT_SU else 'sudo').lower()
|
||||
DEFAULT_BECOME = get_config(p, 'privilege_escalation', 'become', 'ANSIBLE_BECOME',False, value_type='boolean')
|
||||
DEFAULT_BECOME = get_config(p, 'privilege_escalation', 'become', 'ANSIBLE_BECOME', False, value_type='boolean')
|
||||
DEFAULT_BECOME_USER = get_config(p, 'privilege_escalation', 'become_user', 'ANSIBLE_BECOME_USER', 'root')
|
||||
DEFAULT_BECOME_EXE = get_config(p, 'privilege_escalation', 'become_exe', 'ANSIBLE_BECOME_EXE', None)
|
||||
DEFAULT_BECOME_FLAGS = get_config(p, 'privilege_escalation', 'become_flags', 'ANSIBLE_BECOME_FLAGS', None)
|
||||
|
@ -333,7 +334,7 @@ DEFAULT_TEST_PLUGIN_PATH = get_config(p, DEFAULTS, 'test_plugins', 'ANSIBL
|
|||
DEFAULT_STRATEGY_PLUGIN_PATH = get_config(p, DEFAULTS, 'strategy_plugins', 'ANSIBLE_STRATEGY_PLUGINS',
|
||||
'~/.ansible/plugins/strategy:/usr/share/ansible/plugins/strategy', value_type='pathlist')
|
||||
|
||||
NETWORK_GROUP_MODULES = get_config(p, DEFAULTS, 'network_group_modules','NETWORK_GROUP_MODULES', ['eos', 'nxos', 'ios', 'iosxr', 'junos',
|
||||
NETWORK_GROUP_MODULES = get_config(p, DEFAULTS, 'network_group_modules', 'NETWORK_GROUP_MODULES', ['eos', 'nxos', 'ios', 'iosxr', 'junos',
|
||||
'vyos', 'sros', 'dellos9', 'dellos10', 'dellos6'],
|
||||
value_type='list')
|
||||
DEFAULT_STRATEGY = get_config(p, DEFAULTS, 'strategy', 'ANSIBLE_STRATEGY', 'linear')
|
||||
|
@ -363,12 +364,12 @@ RETRY_FILES_ENABLED = get_config(p, DEFAULTS, 'retry_files_enabled',
|
|||
RETRY_FILES_SAVE_PATH = get_config(p, DEFAULTS, 'retry_files_save_path', 'ANSIBLE_RETRY_FILES_SAVE_PATH', None, value_type='path')
|
||||
DEFAULT_NULL_REPRESENTATION = get_config(p, DEFAULTS, 'null_representation', 'ANSIBLE_NULL_REPRESENTATION', None, value_type='none')
|
||||
DISPLAY_ARGS_TO_STDOUT = get_config(p, DEFAULTS, 'display_args_to_stdout', 'ANSIBLE_DISPLAY_ARGS_TO_STDOUT', False, value_type='boolean')
|
||||
MAX_FILE_SIZE_FOR_DIFF = get_config(p, DEFAULTS, 'max_diff_size', 'ANSIBLE_MAX_DIFF_SIZE', 1024*1024, value_type='integer')
|
||||
MAAX_FILE_SIZE_FOR_DIFF = get_config(p, DEFAULTS, 'max_diff_size', 'ANSIBLE_MAX_DIFF_SIZE', 1024 * 1024, value_type='integer')
|
||||
|
||||
# CONNECTION RELATED
|
||||
USE_PERSISTENT_CONNECTIONS = get_config(p, DEFAULTS, 'use_persistent_connections', 'ANSIBLE_USE_PERSISTENT_CONNECTIONS', False, value_type='boolean')
|
||||
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', '-C -o ControlMaster=auto -o ControlPersist=60s')
|
||||
### WARNING: Someone might be tempted to switch this from percent-formatting
|
||||
# WARNING: Someone might be tempted to switch this from percent-formatting
|
||||
# to .format() in the future. be sure to read this:
|
||||
# http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/ and understand
|
||||
# that it may be a security risk to do so.
|
||||
|
@ -406,7 +407,7 @@ GALAXY_ROLE_SKELETON_IGNORE = get_config(p, 'galaxy', 'role_skeleton_ignore', 'A
|
|||
value_type='list')
|
||||
|
||||
STRING_TYPE_FILTERS = get_config(p, 'jinja2', 'dont_type_filters', 'ANSIBLE_STRING_TYPE_FILTERS',
|
||||
['string', 'to_json', 'to_nice_json', 'to_yaml', 'ppretty', 'json'], value_type='list' )
|
||||
['string', 'to_json', 'to_nice_json', 'to_yaml', 'ppretty', 'json'], value_type='list')
|
||||
|
||||
# colors
|
||||
COLOR_HIGHLIGHT = get_config(p, 'colors', 'highlight', 'ANSIBLE_COLOR_HIGHLIGHT', 'white')
|
||||
|
@ -445,4 +446,3 @@ BLACKLIST_EXTS = ('.pyc', '.swp', '.bak', '~', '.rpm', '.md', '.txt')
|
|||
IGNORE_FILES = ["COPYING", "CONTRIBUTING", "LICENSE", "README", "VERSION", "GUIDELINES"]
|
||||
INTERNAL_RESULT_KEYS = ['add_host', 'add_group']
|
||||
RESTRICTED_RESULT_KEYS = ['ansible_rsync_path', 'ansible_playbook_python']
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ lib/ansible/cli/galaxy.py
|
|||
lib/ansible/cli/playbook.py
|
||||
lib/ansible/cli/pull.py
|
||||
lib/ansible/cli/vault.py
|
||||
lib/ansible/constants.py
|
||||
lib/ansible/executor/__init__.py
|
||||
lib/ansible/executor/action_write_locks.py
|
||||
lib/ansible/executor/module_common.py
|
||||
|
|
Loading…
Reference in a new issue