Skip to content

Instantly share code, notes, and snippets.

@bcoca
Last active March 11, 2020 14:28
Show Gist options
  • Save bcoca/5249bd7c7b090ff25bf22b673e4f43ad to your computer and use it in GitHub Desktop.
Save bcoca/5249bd7c7b090ff25bf22b673e4f43ad to your computer and use it in GitHub Desktop.
diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py
index c5cb9d518..df2be2bb0 100644
--- a/awx/main/management/commands/inventory_import.py
+++ b/awx/main/management/commands/inventory_import.py
@@ -661,11 +661,13 @@ class Command(BaseCommand):
if group_name in existing_group_names:
continue
mem_group = self.all_group.all_groups[group_name]
+ import_vars = json.dumps(mem_group.variables)
+ group_desc = import_vars.pop('_awx_description', 'imported')
group = self.inventory.groups.update_or_create(
name=group_name,
defaults={
- 'variables':json.dumps(mem_group.variables),
- 'description':'imported'
+ 'variables': import_vars,
+ 'description': group_desc
}
)[0]
logger.debug('Group "%s" added', group.name)
@@ -788,8 +790,9 @@ class Command(BaseCommand):
# Create any new hosts.
for mem_host_name in sorted(mem_host_names_to_update):
mem_host = self.all_group.all_hosts[mem_host_name]
- host_attrs = dict(variables=json.dumps(mem_host.variables),
- description='imported')
+ import_vars = json.dumps(mem_host.variables)
+ host_desc = import_vars.pop('_awx_description', 'imported')
+ host_attrs = dict(variables=import_vars, description=host_desc)
enabled = self._get_enabled(mem_host.variables)
if enabled is not None:
host_attrs['enabled'] = enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment