Allow parent groups to be variables or literal (#53649)

* Allow parent groups to be variables or literal, requires {{ }}
* Check strict before failing on templating errors
* Don't add a group if an invalid parent group was provided
This commit is contained in:
Sloane Hertel 2019-03-14 13:22:18 -05:00 committed by Brian Coca
commit 87ebc56de6
3 changed files with 75 additions and 0 deletions

View file

@ -404,6 +404,13 @@ class Constructable(object):
prefix = keyed.get('prefix', '')
sep = keyed.get('separator', '_')
raw_parent_name = keyed.get('parent_group', None)
if raw_parent_name:
try:
raw_parent_name = self.templar.template(raw_parent_name)
except AnsibleError as e:
if strict:
raise AnsibleParserError("Could not generate parent group %s for group %s: %s" % (raw_parent_name, key, to_native(e)))
continue
new_raw_group_names = []
if isinstance(key, string_types):