From b151f5d942075096daf2214c78859c6799073419 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 22 Jan 2018 16:16:11 -0800 Subject: [PATCH] Move module_set_locale and module_lang back to global These config settings are being deprecated so we don't want people to think they need to implement them for their new shell plugin. --- lib/ansible/config/base.yml | 25 +++++++++++++++++++ lib/ansible/constants.py | 6 ++--- lib/ansible/plugins/shell/__init__.py | 17 ++++++------- .../module_docs_fragments/shell_common.py | 23 ----------------- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 8ce62536ee6..6bb7d7dee76 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -744,6 +744,19 @@ DEFAULT_MODULE_COMPRESSION: - {key: module_compression, section: defaults} # vars: # - name: ansible_module_compression +DEFAULT_MODULE_LANG: + name: Target language environment + default: "{{ CONTROLLER_LANG }}" + description: + - "Language locale setting to use for modules when they execute on the target." + - "If empty it tries to set itself to the LANG environment variable on the controller." + - "This is only used if DEFAULT_MODULE_SET_LOCALE is set to true" + env: [{name: ANSIBLE_MODULE_LANG}] + ini: + - {key: module_lang, section: defaults} + deprecated: + why: Modules are coded to set their own locale if needed for screenscraping + version: "2.9" DEFAULT_MODULE_NAME: name: Default adhoc module default: command @@ -759,6 +772,18 @@ DEFAULT_MODULE_PATH: ini: - {key: library, section: defaults} type: pathspec +DEFAULT_MODULE_SET_LOCALE: + name: Target locale + default: False + description: + - Controls if we set locale for modules when executing on the target. + env: [{name: ANSIBLE_MODULE_SET_LOCALE}] + ini: + - {key: module_set_locale, section: defaults} + type: boolean + deprecated: + why: Modules are coded to set their own locale if needed for screenscraping + version: "2.9" DEFAULT_MODULE_UTILS_PATH: name: Module Utils Path description: Colon separated paths in which Ansible will search for Module utils files, which are shared by modules. diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index ccb819fdac4..16d57dbd12c 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -17,14 +17,14 @@ from ansible.module_utils.six import string_types from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value -def _deprecated(msg): +def _deprecated(msg, version='2.8'): ''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write ''' try: from __main__ import display - display.deprecated(msg, version='2.8') + display.deprecated(msg, version=version) except: import sys - sys.stderr.write('[DEPRECATED] %s, to be removed in 2.8' % msg) + sys.stderr.write('[DEPRECATED] %s, to be removed in %s' % (msg, version)) def mk_boolean(value): diff --git a/lib/ansible/plugins/shell/__init__.py b/lib/ansible/plugins/shell/__init__.py index a1ed09e0f29..cfadd39a994 100644 --- a/lib/ansible/plugins/shell/__init__.py +++ b/lib/ansible/plugins/shell/__init__.py @@ -23,6 +23,7 @@ import random import re import time +import ansible.constants as C from ansible.module_utils.six import text_type from ansible.module_utils.six.moves import shlex_quote from ansible.plugins import AnsiblePlugin @@ -36,22 +37,18 @@ class ShellBase(AnsiblePlugin): super(ShellBase, self).__init__() self.env = {} + if C.DEFAULT_MODULE_SET_LOCALE: + module_locale = C.DEFAULT_MODULE_LANG + self.env = {'LANG': module_locale, + 'LC_ALL': module_locale, + 'LC_MESSAGES': module_locale} + self.tempdir = None def set_options(self, task_keys=None, var_options=None, direct=None): super(ShellBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct) - # not all shell modules have this option - if self.get_option('set_module_language'): - self.env.update( - dict( - LANG=self.get_option('module_language'), - LC_ALL=self.get_option('module_language'), - LC_MESSAGES=self.get_option('module_language'), - ) - ) - # set env self.env.update(self.get_option('environment')) diff --git a/lib/ansible/utils/module_docs_fragments/shell_common.py b/lib/ansible/utils/module_docs_fragments/shell_common.py index a1d94dbf7d4..250d6c06d99 100644 --- a/lib/ansible/utils/module_docs_fragments/shell_common.py +++ b/lib/ansible/utils/module_docs_fragments/shell_common.py @@ -38,29 +38,6 @@ options: key: async_dir vars: - name: ansible_async_dir - set_module_language: - default: False - description: Controls if we set locale for modules when executing on the target. - env: - - name: ANSIBLE_MODULE_SET_LOCALE - ini: - - section: defaults - key: module_set_locale - type: boolean - vars: - - name: ansible_module_set_locale - module_language: - description: - - "If 'set_module_language' is true, this is the language language/locale setting to use for modules when they execute on the target." - - "Defaults to match the controller's settings." - default: "{{CONTROLLER_LANG}}" - env: - - name: ANSIBLE_MODULE_LANG - ini: - - section: defaults - key: module_lang - vars: - - name: ansible_module_lang environment: type: dict default: {}