add new '@<plugin>:' std inline inventory plugins

pull/83739/head
Brian Coca 4 months ago
parent 1751a79b30
commit 1a970ef18a

@ -1640,7 +1640,7 @@ INVENTORY_ANY_UNPARSED_IS_FAILED:
version_added: "2.7"
INVENTORY_ENABLED:
name: Active Inventory plugins
default: ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml']
default: ['script', 'auto', 'yaml', 'ini', 'toml']
description: List of enabled inventory plugins, it also determines the order in which they are used.
env: [{name: ANSIBLE_INVENTORY_ENABLED}]
ini:

@ -21,6 +21,9 @@ EXAMPLES = """
# all installed inventory plugins.
"""
import os
import re
from ansible.errors import AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.plugins.loader import inventory_loader
@ -29,15 +32,28 @@ from ansible.plugins.loader import inventory_loader
class InventoryModule(BaseInventoryPlugin):
NAME = 'auto'
TOKEN = re.compile('@(\w+):.+')
def verify_file(self, path):
if not path.endswith('.yml') and not path.endswith('.yaml'):
return False
if os.path.exists(path):
if not path.endswith('.yml') and not path.endswith('.yaml'):
return False
elif ',' in path:
return True
return super(InventoryModule, self).verify_file(path)
def parse(self, inventory, loader, path, cache=True):
config_data = loader.load_from_file(path, cache='none')
if os.path.exists(path):
config_data = loader.load_from_file(path, cache='none')
else:
found = self.TOKEN.match(path)
if found:
config_data = {'plugin': found.group(1)}
else:
# fallback to host_list
config_data = {'plugin': 'host_list'}
try:
plugin_name = config_data.get('plugin', None)
except AttributeError:

Loading…
Cancel
Save