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" version_added: "2.7"
INVENTORY_ENABLED: INVENTORY_ENABLED:
name: Active Inventory plugins 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. description: List of enabled inventory plugins, it also determines the order in which they are used.
env: [{name: ANSIBLE_INVENTORY_ENABLED}] env: [{name: ANSIBLE_INVENTORY_ENABLED}]
ini: ini:

@ -21,6 +21,9 @@ EXAMPLES = """
# all installed inventory plugins. # all installed inventory plugins.
""" """
import os
import re
from ansible.errors import AnsibleParserError from ansible.errors import AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.plugins.loader import inventory_loader from ansible.plugins.loader import inventory_loader
@ -29,15 +32,28 @@ from ansible.plugins.loader import inventory_loader
class InventoryModule(BaseInventoryPlugin): class InventoryModule(BaseInventoryPlugin):
NAME = 'auto' NAME = 'auto'
TOKEN = re.compile('@(\w+):.+')
def verify_file(self, path): def verify_file(self, path):
if not path.endswith('.yml') and not path.endswith('.yaml'): if os.path.exists(path):
return False if not path.endswith('.yml') and not path.endswith('.yaml'):
return False
elif ',' in path:
return True
return super(InventoryModule, self).verify_file(path) return super(InventoryModule, self).verify_file(path)
def parse(self, inventory, loader, path, cache=True): 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: try:
plugin_name = config_data.get('plugin', None) plugin_name = config_data.get('plugin', None)
except AttributeError: except AttributeError:

Loading…
Cancel
Save