mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
Add toml inventory plugin (#41593)
* First pass at a toml inventory * Make EXAMPLES yaml * Remove unnecessary comment * Small formatting changes * Add ansible-inventory option to list as TOML * TOML inventory improvements, to allow a more simple inventory, specifically related to children * changelog * Simplify logic * Dedupe _expand_hostpattern, making it available to all inventory plugins * Don't make the TOML inventory dependent on the YAML inventory * Quote IP address values * Add more TOML examples * Further cleanups * Enable the toml inventory to run by default * Create toml specific dumper * 2.8 * Clean up imports * No toml pygments lexer * Don't raise an exception early when toml isn't present, and move toml to the end, since it requires an external dep * Require toml>=0.10.0 * Further clean up of empty data * Don't require toml>=0.10.0, but prefer it, add code for fallback in older versions * Ensure we actually pass an encoder to toml.dumps * Simplify recursive data converter * Appease tests, since we haven't limited controller testing to 2.7+ * Update docstring for convert_yaml_objects_to_native * remove outdated catching of AttributeError * We don't need to catch ImportError when import ansible.plugins.inventory.toml * Add note about what self.dump_funcs.update is doing * Address some things * A little extra comment * Fix toml availability check * Don't create an intermediate list * Require toml file extension * Add metadata * Remove TOML docs from intro_inventory to prevent people from getting the wrong idea * It's in defaults, remove note * core supported, indicate very clearly that this is preview status
This commit is contained in:
parent
1441c6ad3f
commit
9949629e5a
8 changed files with 353 additions and 83 deletions
|
@ -73,8 +73,7 @@ EXAMPLES = '''
|
|||
import ast
|
||||
import re
|
||||
|
||||
from ansible.plugins.inventory import BaseFileInventoryPlugin, detect_range, expand_hostname_range
|
||||
from ansible.parsing.utils.addresses import parse_address
|
||||
from ansible.plugins.inventory import BaseFileInventoryPlugin
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
|
@ -311,32 +310,6 @@ class InventoryModule(BaseFileInventoryPlugin):
|
|||
|
||||
return hostnames, port, variables
|
||||
|
||||
def _expand_hostpattern(self, hostpattern):
|
||||
'''
|
||||
Takes a single host pattern and returns a list of hostnames and an
|
||||
optional port number that applies to all of them.
|
||||
'''
|
||||
|
||||
# Can the given hostpattern be parsed as a host with an optional port
|
||||
# specification?
|
||||
|
||||
try:
|
||||
(pattern, port) = parse_address(hostpattern, allow_ranges=True)
|
||||
except Exception:
|
||||
# not a recognizable host pattern
|
||||
pattern = hostpattern
|
||||
port = None
|
||||
|
||||
# Once we have separated the pattern, we expand it into list of one or
|
||||
# more hostnames, depending on whether it contains any [x:y] ranges.
|
||||
|
||||
if detect_range(pattern):
|
||||
hostnames = expand_hostname_range(pattern)
|
||||
else:
|
||||
hostnames = [pattern]
|
||||
|
||||
return (hostnames, port)
|
||||
|
||||
@staticmethod
|
||||
def _parse_value(v):
|
||||
'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue