Add support for importing host/group descriptions

Signed-off-by: Darin Johnson <djohnson@sonifi.com>
This commit is contained in:
Darin Johnson
2020-03-11 15:17:14 -05:00
parent 8b768bcb01
commit 6cd4b1c666

View File

@@ -661,11 +661,12 @@ class Command(BaseCommand):
if group_name in existing_group_names: if group_name in existing_group_names:
continue continue
mem_group = self.all_group.all_groups[group_name] mem_group = self.all_group.all_groups[group_name]
group_desc = mem_group.variables.pop('_awx_description', 'imported')
group = self.inventory.groups.update_or_create( group = self.inventory.groups.update_or_create(
name=group_name, name=group_name,
defaults={ defaults={
'variables':json.dumps(mem_group.variables), 'variables':json.dumps(mem_group.variables),
'description':'imported' 'description':group_desc
} }
)[0] )[0]
logger.debug('Group "%s" added', group.name) logger.debug('Group "%s" added', group.name)
@@ -788,8 +789,9 @@ class Command(BaseCommand):
# Create any new hosts. # Create any new hosts.
for mem_host_name in sorted(mem_host_names_to_update): for mem_host_name in sorted(mem_host_names_to_update):
mem_host = self.all_group.all_hosts[mem_host_name] mem_host = self.all_group.all_hosts[mem_host_name]
host_attrs = dict(variables=json.dumps(mem_host.variables), import_vars = mem_host.variables
description='imported') host_desc = import_vars.pop('_awx_description', 'imported')
host_attrs = dict(variables=json.dumps(import_vars), description=host_desc)
enabled = self._get_enabled(mem_host.variables) enabled = self._get_enabled(mem_host.variables)
if enabled is not None: if enabled is not None:
host_attrs['enabled'] = enabled host_attrs['enabled'] = enabled