mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
fix 'return false' from parse
this was abandoned early on the manger side but seems like we left behind on plugin side. more flexible extensions with yaml plugin validate data correctly for yaml/constructed fixed issue with only adding one child to keyed, the group only got the host that forced it's creation fixes #31382 fixes #31365
This commit is contained in:
parent
f2ade09dce
commit
e4c61ea9a1
5 changed files with 28 additions and 19 deletions
|
@ -10,7 +10,7 @@ DOCUMENTATION = '''
|
|||
version_added: "2.4"
|
||||
short_description: Uses Jinja2 to construct vars and groups based on existing inventory.
|
||||
description:
|
||||
- Uses a YAML configuration file with a ``.config`` extension to define var expresisions and group conditionals
|
||||
- Uses a YAML configuration file with a valid YAML or ``.config`` extension to define var expressions and group conditionals
|
||||
- The Jinja2 conditionals that qualify a host for membership.
|
||||
- The JInja2 exprpessions are calculated and assigned to the variables
|
||||
- Only variables already available from previous inventories or the fact cache can be used for templating.
|
||||
|
@ -54,6 +54,9 @@ EXAMPLES = '''
|
|||
|
||||
import os
|
||||
|
||||
from collections import MutableMapping
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||
from ansible.module_utils._text import to_native
|
||||
|
@ -75,7 +78,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
if super(InventoryModule, self).verify_file(path):
|
||||
file_name, ext = os.path.splitext(path)
|
||||
|
||||
if not ext or ext == '.config':
|
||||
if not ext or ext in ['.config'] + C.YAML_FILENAME_EXTENSIONS:
|
||||
valid = True
|
||||
|
||||
return valid
|
||||
|
@ -92,6 +95,8 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
|
||||
if not data:
|
||||
raise AnsibleParserError("%s is empty" % (to_native(path)))
|
||||
elif not isinstance(data, MutableMapping):
|
||||
raise AnsibleParserError('inventory source has invalid structure, it should be a dictionary, got: %s' % type(data))
|
||||
elif data.get('plugin') != self.NAME:
|
||||
raise AnsibleParserError("%s is not a constructed groups config file, plugin entry must be 'constructed'" % (to_native(path)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue