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.
This commit is contained in:
Toshio Kuratomi 2018-01-22 16:16:11 -08:00
parent 62bc714dae
commit b151f5d942
4 changed files with 35 additions and 36 deletions

View file

@ -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.

View file

@ -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):

View file

@ -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'))

View file

@ -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: {}