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-worker[0-9]*.open*.org
|
||||||
- logstash[0-9]*.open*.org
|
- logstash[0-9]*.open*.org
|
||||||
- mirror-update[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[0-9]*.openstack.org
|
||||||
- openstackid-dev[0-9]*.openstack.org
|
- openstackid-dev[0-9]*.openstack.org
|
||||||
- paste[0-9]*.open*.org
|
- paste[0-9]*.open*.org
|
||||||
|
@ -39,6 +39,11 @@ results:
|
|||||||
- puppet
|
- puppet
|
||||||
- puppet4
|
- puppet4
|
||||||
|
|
||||||
|
mirror01.lon1.linaro-london.openstack.org:
|
||||||
|
- afs-client
|
||||||
|
- mirror
|
||||||
|
- puppet
|
||||||
|
|
||||||
mirror-update01.openstack.org:
|
mirror-update01.openstack.org:
|
||||||
- afsadmin
|
- afsadmin
|
||||||
- puppet
|
- puppet
|
||||||
|
@ -37,7 +37,7 @@ class TestInventory(testtools.TestCase):
|
|||||||
|
|
||||||
results_yaml = os.path.join(FIXTURE_DIR, 'results.yaml')
|
results_yaml = os.path.join(FIXTURE_DIR, 'results.yaml')
|
||||||
with open(results_yaml) as f:
|
with open(results_yaml) as f:
|
||||||
results = yaml.load(f)
|
results = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
results = results['results']
|
results = results['results']
|
||||||
|
|
||||||
# Build the inventory list. This is a list of Host objects
|
# 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
|
# real-life, which gets the groups into the config object
|
||||||
path = os.path.join(FIXTURE_DIR, 'groups.yaml')
|
path = os.path.join(FIXTURE_DIR, 'groups.yaml')
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
config_groups = yaml.load(f)
|
config_groups = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
config_groups = config_groups['groups']
|
config_groups = config_groups['groups']
|
||||||
im = InventoryModule()
|
im = InventoryModule()
|
||||||
im._read_config_data = mock.MagicMock()
|
im._read_config_data = mock.MagicMock()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from ansible.parsing.yaml.objects import AnsibleMapping
|
from ansible.parsing.yaml.objects import AnsibleMapping
|
||||||
from ansible.plugins.inventory import BaseFileInventoryPlugin
|
from ansible.plugins.inventory import BaseFileInventoryPlugin
|
||||||
@ -28,7 +29,10 @@ DOCUMENTATION = '''
|
|||||||
- section: inventory_plugin_yaml
|
- section: inventory_plugin_yaml
|
||||||
key: yaml_valid_extensions
|
key: yaml_valid_extensions
|
||||||
groups:
|
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
|
type: dict
|
||||||
default: {}
|
default: {}
|
||||||
'''
|
'''
|
||||||
@ -38,6 +42,7 @@ groups:
|
|||||||
amazing:
|
amazing:
|
||||||
- fullhost.example.com
|
- fullhost.example.com
|
||||||
- amazing*
|
- amazing*
|
||||||
|
- ^regex.*pattern
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@ -75,8 +80,16 @@ class InventoryModule(BaseFileInventoryPlugin):
|
|||||||
# failing.
|
# failing.
|
||||||
if isinstance(candidate, AnsibleMapping):
|
if isinstance(candidate, AnsibleMapping):
|
||||||
candidate = list(candidate.keys())[0]
|
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():
|
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.setdefault(group, [])
|
||||||
found_groups[group].append(existing)
|
found_groups[group].append(existing)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user