Merge pull request #6338 from wenottingham/yes-we-are-enablers

[RFC] Allow setting enabled/disabled and other flags for custom inventory sources
This commit is contained in:
Bill Nottingham
2017-05-25 17:27:49 -04:00
committed by GitHub
2 changed files with 37 additions and 38 deletions

View File

@@ -1755,52 +1755,41 @@ class RunInventoryUpdate(BaseTask):
args.append('--overwrite') args.append('--overwrite')
if inventory_update.overwrite_vars: if inventory_update.overwrite_vars:
args.append('--overwrite-vars') args.append('--overwrite-vars')
args.append('--source') src = inventory_update.source
# If this is a cloud-based inventory (e.g. from AWS, Rackspace, etc.)
# then we need to set some extra flags based on settings in # Add several options to the shell arguments based on the
# Tower. # inventory-source-specific setting in the Tower configuration.
# # These settings are "per-source"; it's entirely possible that
# These settings are "per-cloud-provider"; it's entirely possible that
# they will be different between cloud providers if a Tower user # they will be different between cloud providers if a Tower user
# actively uses more than one. # actively uses more than one.
if inventory_update.source in CLOUD_PROVIDERS: if getattr(settings, '%s_ENABLED_VAR' % src.upper(), False):
# We need to reference the source's code frequently, assign it args.extend(['--enabled-var',
# to a shorter variable. :) getattr(settings, '%s_ENABLED_VAR' % src.upper())])
src = inventory_update.source if getattr(settings, '%s_ENABLED_VALUE' % src.upper(), False):
args.extend(['--enabled-value',
getattr(settings, '%s_ENABLED_VALUE' % src.upper())])
if getattr(settings, '%s_GROUP_FILTER' % src.upper(), False):
args.extend(['--group-filter',
getattr(settings, '%s_GROUP_FILTER' % src.upper())])
if getattr(settings, '%s_HOST_FILTER' % src.upper(), False):
args.extend(['--host-filter',
getattr(settings, '%s_HOST_FILTER' % src.upper())])
if getattr(settings, '%s_EXCLUDE_EMPTY_GROUPS' % src.upper()):
args.append('--exclude-empty-groups')
if getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper(), False):
args.extend(['--instance-id-var',
getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper()),])
# Add arguments for the source inventory script
args.append('--source')
if src in CLOUD_PROVIDERS:
# Get the path to the inventory plugin, and append it to our # Get the path to the inventory plugin, and append it to our
# arguments. # arguments.
plugin_path = self.get_path_to('..', 'plugins', 'inventory', plugin_path = self.get_path_to('..', 'plugins', 'inventory',
'%s.py' % src) '%s.py' % src)
args.append(plugin_path) args.append(plugin_path)
elif src == 'scm':
# Add several options to the shell arguments based on the
# cloud-provider-specific setting in the Tower configuration.
args.extend(['--enabled-var',
getattr(settings, '%s_ENABLED_VAR' % src.upper())])
args.extend(['--enabled-value',
getattr(settings, '%s_ENABLED_VALUE' % src.upper())])
args.extend(['--group-filter',
getattr(settings, '%s_GROUP_FILTER' % src.upper())])
args.extend(['--host-filter',
getattr(settings, '%s_HOST_FILTER' % src.upper())])
# We might have a flag set to exclude empty groups; if we do,
# add that flag to the shell arguments.
if getattr(settings, '%s_EXCLUDE_EMPTY_GROUPS' % src.upper()):
args.append('--exclude-empty-groups')
# We might have a flag for an instance ID variable; if we do,
# add it to the shell arguments.
if getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper(), False):
args.extend([
'--instance-id-var',
getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper()),
])
elif inventory_update.source == 'scm':
args.append(inventory_update.get_actual_source_path()) args.append(inventory_update.get_actual_source_path())
elif inventory_update.source == 'custom': elif src == 'custom':
runpath = tempfile.mkdtemp(prefix='ansible_tower_launch_') runpath = tempfile.mkdtemp(prefix='ansible_tower_launch_')
handle, path = tempfile.mkstemp(dir=runpath) handle, path = tempfile.mkstemp(dir=runpath)
f = os.fdopen(handle, 'w') f = os.fdopen(handle, 'w')

View File

@@ -805,6 +805,16 @@ CLOUDFORMS_HOST_FILTER = r'^.+$'
CLOUDFORMS_EXCLUDE_EMPTY_GROUPS = True CLOUDFORMS_EXCLUDE_EMPTY_GROUPS = True
CLOUDFORMS_INSTANCE_ID_VAR = 'id' CLOUDFORMS_INSTANCE_ID_VAR = 'id'
# ---------------------
# ----- Custom -----
# ---------------------
#CUSTOM_ENABLED_VAR =
#CUSTOM_ENABLED_VALUE =
CUSTOM_GROUP_FILTER = r'^.+$'
CUSTOM_HOST_FILTER = r'^.+$'
CUSTOM_EXCLUDE_EMPTY_GROUPS = True
#CUSTOM_INSTANCE_ID_VAR =
# --------------------- # ---------------------
# -- Activity Stream -- # -- Activity Stream --
# --------------------- # ---------------------