Merge "yamlgroup: add regex match; exclude puppet4 for arm64 mirrors"
This commit is contained in:
commit
73fc6dde7c
@ -175,7 +175,7 @@ groups:
|
||||
- logstash-worker[0-9]*.open*.org
|
||||
- logstash[0-9]*.open*.org
|
||||
- mirror-update[0-9]*.open*.org
|
||||
- mirror[0-9]*.*.*.open*.org
|
||||
- ^mirror[0-9].*\..*\.(?!linaro|linaro-london|arm64ci).*\.open.*\.org
|
||||
- openstackid[0-9]*.openstack.org
|
||||
- openstackid-dev[0-9]*.openstack.org
|
||||
- paste[0-9]*.open*.org
|
||||
|
@ -39,6 +39,11 @@ results:
|
||||
- puppet
|
||||
- puppet4
|
||||
|
||||
mirror01.lon1.linaro-london.openstack.org:
|
||||
- afs-client
|
||||
- mirror
|
||||
- puppet
|
||||
|
||||
mirror-update01.openstack.org:
|
||||
- afsadmin
|
||||
- puppet
|
||||
|
@ -37,7 +37,7 @@ class TestInventory(testtools.TestCase):
|
||||
|
||||
results_yaml = os.path.join(FIXTURE_DIR, 'results.yaml')
|
||||
with open(results_yaml) as f:
|
||||
results = yaml.load(f)
|
||||
results = yaml.load(f, Loader=yaml.FullLoader)
|
||||
results = results['results']
|
||||
|
||||
# Build the inventory list. This is a list of Host objects
|
||||
@ -65,7 +65,7 @@ class TestInventory(testtools.TestCase):
|
||||
# real-life, which gets the groups into the config object
|
||||
path = os.path.join(FIXTURE_DIR, 'groups.yaml')
|
||||
with open(path) as f:
|
||||
config_groups = yaml.load(f)
|
||||
config_groups = yaml.load(f, Loader=yaml.FullLoader)
|
||||
config_groups = config_groups['groups']
|
||||
im = InventoryModule()
|
||||
im._read_config_data = mock.MagicMock()
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
import fnmatch
|
||||
import os
|
||||
import re
|
||||
|
||||
from ansible.parsing.yaml.objects import AnsibleMapping
|
||||
from ansible.plugins.inventory import BaseFileInventoryPlugin
|
||||
@ -28,7 +29,10 @@ DOCUMENTATION = '''
|
||||
- section: inventory_plugin_yaml
|
||||
key: yaml_valid_extensions
|
||||
groups:
|
||||
description: dict with group name as key and list of fnmatch patterns
|
||||
description: |
|
||||
dict with group name as key. If the list item starts with a
|
||||
^ it will be considered a regex pattern (i.e. passed to
|
||||
re.match), otherwise it is considered a fnmatch pattern.
|
||||
type: dict
|
||||
default: {}
|
||||
'''
|
||||
@ -38,6 +42,7 @@ groups:
|
||||
amazing:
|
||||
- fullhost.example.com
|
||||
- amazing*
|
||||
- ^regex.*pattern
|
||||
'''
|
||||
|
||||
|
||||
@ -75,8 +80,16 @@ class InventoryModule(BaseFileInventoryPlugin):
|
||||
# failing.
|
||||
if isinstance(candidate, AnsibleMapping):
|
||||
candidate = list(candidate.keys())[0]
|
||||
|
||||
# Starts with ^ means it is already a regex.
|
||||
# Otherwise it's a fnmatch compatible string; use it's
|
||||
# helper to turn that into a regex so we have a common
|
||||
# match below.
|
||||
if not candidate.startswith('^'):
|
||||
candidate = fnmatch.translate(candidate)
|
||||
|
||||
for existing in self.inventory.hosts.values():
|
||||
if fnmatch.fnmatch(existing.get_name(), candidate):
|
||||
if re.match(candidate, existing.get_name()):
|
||||
found_groups.setdefault(group, [])
|
||||
found_groups[group].append(existing)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user