0 0 ?÷# Copyright: (c) 2012-2014, Michael DeHaan # Copyright: (c) 2016, Toshio Kuratomi # Copyright: (c) 2018, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type import locale import os import sys # Used for determining if the system is running a new enough python version # and should only restrict on our documented minimum versions if sys.version_info < (3, 9): raise SystemExit( 'ERROR: Ansible requires Python 3.9 or newer on the controller. ' 'Current version: %s' % ''.join(sys.version.splitlines()) ) def check_blocking_io(): """Check stdin/stdout/stderr to make sure they are using blocking IO.""" handles = [] for handle in (sys.stdin, sys.stdout, sys.stderr): # noinspection PyBroadException try: fd = handle.fileno() except Exception: continue # not a real file handle, such as during the import sanity test if not os.get_blocking(fd): handles.append(getattr(handle, 'name', None) or '#%s' % fd) if handles: raise SystemExit('ERROR: Ansible requires blocking IO on stdin/stdout/stderr. ' 'Non-blocking file handles detected: %s' % ', '.join(_io for _io in handles)) check_blocking_io() def initialize_locale(): """Set the locale to the users default setting and ensure the locale and filesystem encoding are UTF-8. """ try: locale.setlocale(locale.LC_ALL, '') dummy, encoding = locale.getlocale() except (locale.Error, ValueError) as e: raise SystemExit( 'ERROR: Ansible could not initialize the preferred locale: %s' % e ) if not encoding or encoding.lower() not in ('utf-8', 'utf8'): raise SystemExit('ERROR: Ansible requires the locale encoding to be UTF-8; Detected %s.' % encoding) fs_enc = sys.getfilesystemencoding() if fs_enc.lower() != 'utf-8': raise SystemExit('ERROR: Ansible requires the filesystem encoding to be UTF-8; Detected %s.' % fs_enc) initialize_locale() from importlib.metadata import version from ansible.module_utils.compat.version import LooseVersion # Used for determining if the system is running a new enough Jinja2 version # and should only restrict on our documented minimum versions jinja2_version = version('jinja2') if jinja2_version < LooseVersion('3.0'): raise SystemExit( 'ERROR: Ansible requires Jinja2 3.0 or newer on the controller. ' 'Current version: %s' % jinja2_version ) import errno import getpass import subprocess import traceback from abc import ABC, abstractmethod from pathlib import Path try: from ansible import constants as C from ansible.utils.display import Display display = Display() except Exception as e: print('ERROR: %s' % e, file=sys.stderr) sys.exit(5) from ansible import context from ansible.cli.arguments import option_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError from ansible.inventory.manager import InventoryManager from ansible.module_utils.six import string_types from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils.common.file import is_executable from ansible.parsing.dataloader import DataLoader from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret from ansible.plugins.loader import add_all_plugin_dirs from ansible.release import __version__ from ansible.utils.collection_loader import AnsibleCollectionConfig from ansible.utils.collection_loader._collection_finder import _get_collection_name_from_path from ansible.utils.path import unfrackpath from ansible.utils.unsafe_proxy import to_unsafe_text from ansible.vars.manager import VariableManager try: import argcomplete HAS_ARGCOMPLETE = True except ImportError: HAS_ARGCOMPLETE = False