mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ensure 'text' source assumptions (#42522)
* ensure 'text' source assumptions
This commit is contained in:
parent
1c08eb8b27
commit
937e710485
2 changed files with 14 additions and 10 deletions
2
changelogs/fragments/ensure_text_source.yaml
Normal file
2
changelogs/fragments/ensure_text_source.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- remove ambiguity when it comes to 'the source'
|
|
@ -223,7 +223,9 @@ class InventoryManager(object):
|
||||||
parsed = False
|
parsed = False
|
||||||
display.debug(u'Examining possible inventory source: %s' % source)
|
display.debug(u'Examining possible inventory source: %s' % source)
|
||||||
|
|
||||||
|
# use binary for path functions
|
||||||
b_source = to_bytes(source)
|
b_source = to_bytes(source)
|
||||||
|
|
||||||
# process directories as a collection of inventories
|
# process directories as a collection of inventories
|
||||||
if os.path.isdir(b_source):
|
if os.path.isdir(b_source):
|
||||||
display.debug(u'Searching for inventory files in directory: %s' % source)
|
display.debug(u'Searching for inventory files in directory: %s' % source)
|
||||||
|
@ -235,9 +237,9 @@ class InventoryManager(object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# recursively deal with directory entries
|
# recursively deal with directory entries
|
||||||
b_fullpath = os.path.join(b_source, i)
|
fullpath = to_text(os.path.join(b_source, i), errors='surrogate_or_strict')
|
||||||
parsed_this_one = self.parse_source(b_fullpath, cache=cache)
|
parsed_this_one = self.parse_source(fullpath, cache=cache)
|
||||||
display.debug(u'parsed %s as %s' % (to_text(b_fullpath), parsed_this_one))
|
display.debug(u'parsed %s as %s' % (fullpath, parsed_this_one))
|
||||||
if not parsed:
|
if not parsed:
|
||||||
parsed = parsed_this_one
|
parsed = parsed_this_one
|
||||||
else:
|
else:
|
||||||
|
@ -258,7 +260,7 @@ class InventoryManager(object):
|
||||||
|
|
||||||
# initialize and figure out if plugin wants to attempt parsing this file
|
# initialize and figure out if plugin wants to attempt parsing this file
|
||||||
try:
|
try:
|
||||||
plugin_wants = bool(plugin.verify_file(to_text(source)))
|
plugin_wants = bool(plugin.verify_file(source))
|
||||||
except Exception:
|
except Exception:
|
||||||
plugin_wants = False
|
plugin_wants = False
|
||||||
|
|
||||||
|
@ -267,16 +269,16 @@ class InventoryManager(object):
|
||||||
# in case plugin fails 1/2 way we dont want partial inventory
|
# in case plugin fails 1/2 way we dont want partial inventory
|
||||||
plugin.parse(self._inventory, self._loader, source, cache=cache)
|
plugin.parse(self._inventory, self._loader, source, cache=cache)
|
||||||
parsed = True
|
parsed = True
|
||||||
display.vvv('Parsed %s inventory source with %s plugin' % (to_text(source), plugin_name))
|
display.vvv('Parsed %s inventory source with %s plugin' % (source, plugin_name))
|
||||||
break
|
break
|
||||||
except AnsibleParserError as e:
|
except AnsibleParserError as e:
|
||||||
display.debug('%s was not parsable by %s' % (to_text(source), plugin_name))
|
display.debug('%s was not parsable by %s' % (source, plugin_name))
|
||||||
failures.append({'src': source, 'plugin': plugin_name, 'exc': e})
|
failures.append({'src': source, 'plugin': plugin_name, 'exc': e})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
display.debug('%s failed to parse %s' % (plugin_name, to_text(source)))
|
display.debug('%s failed to parse %s' % (plugin_name, source))
|
||||||
failures.append({'src': source, 'plugin': plugin_name, 'exc': AnsibleError(e)})
|
failures.append({'src': source, 'plugin': plugin_name, 'exc': AnsibleError(e)})
|
||||||
else:
|
else:
|
||||||
display.debug('%s did not meet %s requirements' % (to_text(source), plugin_name))
|
display.debug('%s did not meet %s requirements' % (source, plugin_name))
|
||||||
else:
|
else:
|
||||||
if not parsed and failures:
|
if not parsed and failures:
|
||||||
# only if no plugin processed files should we show errors.
|
# only if no plugin processed files should we show errors.
|
||||||
|
@ -285,9 +287,9 @@ class InventoryManager(object):
|
||||||
if hasattr(fail['exc'], 'tb'):
|
if hasattr(fail['exc'], 'tb'):
|
||||||
display.vvv(to_text(fail['exc'].tb))
|
display.vvv(to_text(fail['exc'].tb))
|
||||||
if C.INVENTORY_ANY_UNPARSED_IS_FAILED:
|
if C.INVENTORY_ANY_UNPARSED_IS_FAILED:
|
||||||
raise AnsibleError(u'Completely failed to parse inventory source %s' % (to_text(source)))
|
raise AnsibleError(u'Completely failed to parse inventory source %s' % (source))
|
||||||
if not parsed:
|
if not parsed:
|
||||||
display.warning("Unable to parse %s as an inventory source" % to_text(source))
|
display.warning("Unable to parse %s as an inventory source" % source)
|
||||||
|
|
||||||
# clear up, jic
|
# clear up, jic
|
||||||
self._inventory.current_source = None
|
self._inventory.current_source = None
|
||||||
|
|
Loading…
Reference in a new issue