Skip to content

Commit

Permalink
dont think all files are valid cause libs present (ansible#50103)
Browse files Browse the repository at this point in the history
verify_file was improperly always returning true if pyvimomi and requests libs were correct
  moved library checking to parse, avoid unneded errors unless the file is actually meant for
  this plugin

(cherry picked from commit 49993a5)
  • Loading branch information
bcoca committed Dec 19, 2018
1 parent 85764a0 commit 79528c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/fix_vmware_inv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- correct behaviour of verify_file for vmware inventory plugin, it was always returning True
15 changes: 7 additions & 8 deletions lib/ansible/plugins/inventory/vmware_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,19 @@ def verify_file(self, path):
if path.endswith(('vmware.yaml', 'vmware.yml')):
valid = True

return valid

def parse(self, inventory, loader, path, cache=True):
"""
Parses the inventory file
"""

if not HAS_REQUESTS:
raise AnsibleParserError('Please install "requests" Python module as this is required'
' for VMware Guest dynamic inventory plugin.')
elif not HAS_PYVMOMI:
raise AnsibleParserError('Please install "PyVmomi" Python module as this is required'
' for VMware Guest dynamic inventory plugin.')

if HAS_REQUESTS:
# Pyvmomi 5.5 and onwards requires requests 2.3
# https://github.com/vmware/pyvmomi/blob/master/requirements.txt
Expand All @@ -250,14 +256,7 @@ def verify_file(self, path):
raise AnsibleParserError("'requests' library version should"
" be >= %s, found: %s." % (".".join([str(w) for w in required_version]),
requests.__version__))
valid = True

return valid

def parse(self, inventory, loader, path, cache=True):
"""
Parses the inventory file
"""
super(InventoryModule, self).parse(inventory, loader, path, cache=cache)

cache_key = self.get_cache_key(path)
Expand Down

0 comments on commit 79528c8

Please sign in to comment.