diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 48e1a15509..129e06b854 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1756,7 +1756,7 @@ class RunInventoryUpdate(BaseTask): cp.set(section, 'ssl_verify', "false") cloudforms_opts = dict(inventory_update.source_vars_dict.items()) - for opt in ['version', 'purge_actions', 'clean_group_keys', 'nest_tags']: + for opt in ['version', 'purge_actions', 'clean_group_keys', 'nest_tags', 'suffix']: if opt in cloudforms_opts: cp.set(section, opt, cloudforms_opts[opt]) diff --git a/awx/plugins/inventory/cloudforms.ini.example b/awx/plugins/inventory/cloudforms.ini.example index 142514a65e..1d81588410 100644 --- a/awx/plugins/inventory/cloudforms.ini.example +++ b/awx/plugins/inventory/cloudforms.ini.example @@ -27,6 +27,9 @@ clean_group_keys = True # Explode tags into nested groups / subgroups nest_tags = False +# If set, ensure host name are suffixed with this value +# suffix = example.org + [cache] # Maximum time to trust the cache in seconds diff --git a/awx/plugins/inventory/cloudforms.py b/awx/plugins/inventory/cloudforms.py index 69c149bfc5..25bc032efd 100755 --- a/awx/plugins/inventory/cloudforms.py +++ b/awx/plugins/inventory/cloudforms.py @@ -174,6 +174,11 @@ class CloudFormsInventory(object): else: self.cloudforms_nest_tags = False + if config.has_option('cloudforms', 'suffix'): + self.cloudforms_suffix = config.get('cloudforms', 'suffix') + else: + self.cloudforms_suffix = None + # Ansible related try: group_patterns = config.get('ansible', 'group_patterns') @@ -280,6 +285,9 @@ class CloudFormsInventory(object): print("Updating cache...") for host in self._get_hosts(): + if self.cloudforms_suffix is not None and not host['name'].endswith(self.cloudforms_suffix): + host['name'] = host['name'] + self.cloudforms_suffix + # Ignore VMs that are not powered on if host['power_state'] != 'on': if self.args.debug: