mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
Merge pull request #5313 from fosterseth/fix-5044-azureinventory
Fix filtering azure inventory based on user-specified tags Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -2044,9 +2044,25 @@ class azure_rm(PluginFileInjector):
|
|||||||
for key, loc in old_filterables:
|
for key, loc in old_filterables:
|
||||||
value = source_vars.get(key, None)
|
value = source_vars.get(key, None)
|
||||||
if value and isinstance(value, str):
|
if value and isinstance(value, str):
|
||||||
user_filters.append('{} not in {}'.format(
|
# tags can be list of key:value pairs
|
||||||
loc, value.split(',')
|
# e.g. 'Creator:jmarshall, peanutbutter:jelly'
|
||||||
))
|
# or tags can be a list of keys
|
||||||
|
# e.g. 'Creator, peanutbutter'
|
||||||
|
if key == "tags":
|
||||||
|
# grab each key value pair
|
||||||
|
for kvpair in value.split(','):
|
||||||
|
# split into key and value
|
||||||
|
kv = kvpair.split(':')
|
||||||
|
# filter out any host that does not have key
|
||||||
|
# in their tags.keys() variable
|
||||||
|
user_filters.append('"{}" not in tags.keys()'.format(kv[0].strip()))
|
||||||
|
# if a value is provided, check that the key:value pair matches
|
||||||
|
if len(kv) > 1:
|
||||||
|
user_filters.append('tags["{}"] != "{}"'.format(kv[0].strip(), kv[1].strip()))
|
||||||
|
else:
|
||||||
|
user_filters.append('{} not in {}'.format(
|
||||||
|
loc, value.split(',')
|
||||||
|
))
|
||||||
if user_filters:
|
if user_filters:
|
||||||
ret.setdefault('exclude_host_filters', [])
|
ret.setdefault('exclude_host_filters', [])
|
||||||
ret['exclude_host_filters'].extend(user_filters)
|
ret['exclude_host_filters'].extend(user_filters)
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ conditional_groups:
|
|||||||
default_host_filters: []
|
default_host_filters: []
|
||||||
exclude_host_filters:
|
exclude_host_filters:
|
||||||
- resource_group not in ['foo_resources', 'bar_resources']
|
- resource_group not in ['foo_resources', 'bar_resources']
|
||||||
|
- '"Creator" not in tags.keys()'
|
||||||
|
- tags["Creator"] != "jmarshall"
|
||||||
|
- '"peanutbutter" not in tags.keys()'
|
||||||
|
- tags["peanutbutter"] != "jelly"
|
||||||
- location not in ['southcentralus', 'westus']
|
- location not in ['southcentralus', 'westus']
|
||||||
fail_on_template_errors: false
|
fail_on_template_errors: false
|
||||||
hostvar_expressions:
|
hostvar_expressions:
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ locations = southcentralus,westus
|
|||||||
base_source_var = value_of_var
|
base_source_var = value_of_var
|
||||||
use_private_ip = True
|
use_private_ip = True
|
||||||
resource_groups = foo_resources,bar_resources
|
resource_groups = foo_resources,bar_resources
|
||||||
|
tags = Creator:jmarshall, peanutbutter:jelly
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ INI_TEST_VARS = {
|
|||||||
},
|
},
|
||||||
'azure_rm': {
|
'azure_rm': {
|
||||||
'use_private_ip': True,
|
'use_private_ip': True,
|
||||||
'resource_groups': 'foo_resources,bar_resources'
|
'resource_groups': 'foo_resources,bar_resources',
|
||||||
|
'tags': 'Creator:jmarshall, peanutbutter:jelly'
|
||||||
},
|
},
|
||||||
'satellite6': {
|
'satellite6': {
|
||||||
'satellite6_group_patterns': 'foo_group_patterns',
|
'satellite6_group_patterns': 'foo_group_patterns',
|
||||||
|
|||||||
Reference in New Issue
Block a user