1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #769 from rbywater/feature/cloudformssuffix

Add ability to append suffix to host names for Cloudforms Inventory
This commit is contained in:
Ryan Petrello 2018-01-17 11:43:10 -05:00 committed by GitHub
commit 18f254fc28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -1763,7 +1763,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])

View File

@ -27,6 +27,10 @@ clean_group_keys = True
# Explode tags into nested groups / subgroups
nest_tags = False
# If set, ensure host name are suffixed with this value
# Note: This suffix *must* include the leading '.' as it is appended to the hostname as is
# suffix = .example.org
[cache]
# Maximum time to trust the cache in seconds

View File

@ -29,6 +29,7 @@ from time import time
import requests
from requests.auth import HTTPBasicAuth
import warnings
from ansible.errors import AnsibleError
try:
import json
@ -174,6 +175,13 @@ class CloudFormsInventory(object):
else:
self.cloudforms_nest_tags = False
if config.has_option('cloudforms', 'suffix'):
self.cloudforms_suffix = config.get('cloudforms', 'suffix')
if self.cloudforms_suffix[0] != '.':
raise AnsibleError('Leading fullstop is required for Cloudforms suffix')
else:
self.cloudforms_suffix = None
# Ansible related
try:
group_patterns = config.get('ansible', 'group_patterns')
@ -280,6 +288,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: