mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 13:36:02 -03:30
Add ability to append suffix to host names for Cloudforms Inventory
Allows for use of a suffix that will be appended to host names returned from Cloudforms API if that suffix is not present. For example with a suffix of 'example.org', the following results would be shown for a particular Cloudforms host name: someexample -> someexample.example.org someexample.example.org -> someexample.example.org The main use-case for this is, when one Inventory Source is returning names that have a FQDN name whilst others are returning a shortname, to ensure that the hosts in an inventory aren't effectively duplicated.
This commit is contained in:
@@ -1756,7 +1756,7 @@ class RunInventoryUpdate(BaseTask):
|
|||||||
cp.set(section, 'ssl_verify', "false")
|
cp.set(section, 'ssl_verify', "false")
|
||||||
|
|
||||||
cloudforms_opts = dict(inventory_update.source_vars_dict.items())
|
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:
|
if opt in cloudforms_opts:
|
||||||
cp.set(section, opt, cloudforms_opts[opt])
|
cp.set(section, opt, cloudforms_opts[opt])
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ clean_group_keys = True
|
|||||||
# Explode tags into nested groups / subgroups
|
# Explode tags into nested groups / subgroups
|
||||||
nest_tags = False
|
nest_tags = False
|
||||||
|
|
||||||
|
# If set, ensure host name are suffixed with this value
|
||||||
|
# suffix = example.org
|
||||||
|
|
||||||
[cache]
|
[cache]
|
||||||
|
|
||||||
# Maximum time to trust the cache in seconds
|
# Maximum time to trust the cache in seconds
|
||||||
|
|||||||
@@ -174,6 +174,11 @@ class CloudFormsInventory(object):
|
|||||||
else:
|
else:
|
||||||
self.cloudforms_nest_tags = False
|
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
|
# Ansible related
|
||||||
try:
|
try:
|
||||||
group_patterns = config.get('ansible', 'group_patterns')
|
group_patterns = config.get('ansible', 'group_patterns')
|
||||||
@@ -280,6 +285,9 @@ class CloudFormsInventory(object):
|
|||||||
print("Updating cache...")
|
print("Updating cache...")
|
||||||
|
|
||||||
for host in self._get_hosts():
|
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
|
# Ignore VMs that are not powered on
|
||||||
if host['power_state'] != 'on':
|
if host['power_state'] != 'on':
|
||||||
if self.args.debug:
|
if self.args.debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user