summaryrefslogtreecommitdiff
path: root/lib/ansible/inventory
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2019-03-11 15:12:14 -0400
committerGitHub <noreply@github.com>2019-03-11 15:12:14 -0400
commit9b6721909665813235f2e16615a77459d0853478 (patch)
tree61cbc047b066809595f457bb29e2dba1aac18ead /lib/ansible/inventory
parent86ba4f3e469de56158301ff1b4a68138f09ab1c2 (diff)
downloadansible-9b6721909665813235f2e16615a77459d0853478.tar.gz
Fine tune sanity (#53544)
* modify regex to use implicit charsets this should solve issues in py3 and unicode names * fix issue with subgroups in yaml inventory * clarify deprecation message * separated per name warning from deprecation * move noise to verbosity, simplify warnings * fix docs to reflect actual 'good' practice * change toggle to choice list to give users more options
Diffstat (limited to 'lib/ansible/inventory')
-rw-r--r--lib/ansible/inventory/group.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py
index 55f8aad74f..810d57a271 100644
--- a/lib/ansible/inventory/group.py
+++ b/lib/ansible/inventory/group.py
@@ -31,16 +31,29 @@ display = Display()
def to_safe_group_name(name, replacer="_", force=False, silent=False):
# Converts 'bad' characters in a string to underscores (or provided replacer) so they can be used as Ansible hosts or groups
+ warn = ''
if name: # when deserializing we might not have name yet
invalid_chars = C.INVALID_VARIABLE_NAMES.findall(name)
if invalid_chars:
msg = 'invalid character(s) "%s" in group name (%s)' % (to_text(set(invalid_chars)), to_text(name))
- if C.TRANSFORM_INVALID_GROUP_CHARS or force:
+ if C.TRANSFORM_INVALID_GROUP_CHARS not in ('never', 'ignore') or force:
name = C.INVALID_VARIABLE_NAMES.sub(replacer, name)
- if not silent:
- display.warning('Replacing ' + msg)
+ if not (silent or C.TRANSFORM_INVALID_GROUP_CHARS == 'silently'):
+ display.vvvv('Replacing ' + msg)
+ warn = 'Invalid characters were found in group names and automatically replaced, use -vvvv to see details'
else:
- display.deprecated('Ignoring ' + msg, version='2.12')
+ if C.TRANSFORM_INVALID_GROUP_CHARS == 'never':
+ display.vvvv('Not replacing %s' % msg)
+ warn = True
+ warn = 'Invalid characters were found in group names but not replaced, use -vvvv to see details'
+
+ # remove this message after 2.10 AND changing the default to 'always'
+ display.deprecated('The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default,'
+ ' this will change, but still be user configurable on deprecation', version='2.10')
+
+ if warn:
+ display.warning(warn)
+
return name