Add toggle to control invalid character substitution in group names (#52748)

* make add_group return proper name
* ensure central transform/check
* added 'silent' option to avoid spamming current users
  those already using the plugins were used to the transformations, so no need to alert them
* centralized valid var names
* dont display dupes
* comment on regex
* added regex tests
  ini and script will now warn about deprecation
* more complete errormsg
This commit is contained in:
Brian Coca
2019-03-06 11:49:40 -05:00
committed by GitHub
parent 9c54649449
commit d241794daa
14 changed files with 107 additions and 41 deletions

View File

@@ -156,21 +156,25 @@ class InventoryData(object):
return matching_host
def add_group(self, group):
''' adds a group to inventory if not there already '''
''' adds a group to inventory if not there already, returns named actually used '''
if group:
if not isinstance(group, string_types):
raise AnsibleError("Invalid group name supplied, expected a string but got %s for %s" % (type(group), group))
if group not in self.groups:
g = Group(group)
self.groups[group] = g
self._groups_dict_cache = {}
display.debug("Added group %s to inventory" % group)
if g.name not in self.groups:
self.groups[g.name] = g
self._groups_dict_cache = {}
display.debug("Added group %s to inventory" % group)
group = g.name
else:
display.debug("group %s already in inventory" % group)
else:
raise AnsibleError("Invalid empty/false group name provided: %s" % group)
return group
def remove_group(self, group):
if group in self.groups:
@@ -188,6 +192,8 @@ class InventoryData(object):
if host:
if not isinstance(host, string_types):
raise AnsibleError("Invalid host name supplied, expected a string but got %s for %s" % (type(host), host))
# TODO: add to_safe_host_name
g = None
if group:
if group in self.groups:
@@ -223,6 +229,8 @@ class InventoryData(object):
else:
raise AnsibleError("Invalid empty host name provided: %s" % host)
return host
def remove_host(self, host):
if host.name in self.hosts: