mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Fixes related to uncommenting test_dir_inventory in TestInventory.
0. Uncomment the test. 1. Test fails. 2. Make vars unique per file in test inventory files. 3. Modify token addition to not ast.literal_eval(v) a variable containing a hash. 4. Modify vars to have an escape in test inventory file. 5. Catch exceptions explicitly. Any unknown exceptions should be a bug. 6. Test passes.
This commit is contained in:
parent
616d7e53b1
commit
16fe09eef8
5 changed files with 33 additions and 21 deletions
|
@ -123,12 +123,22 @@ class InventoryParser(object):
|
|||
(k,v) = t.split("=", 1)
|
||||
except ValueError, e:
|
||||
raise errors.AnsibleError("Invalid ini entry: %s - %s" % (t, str(e)))
|
||||
try:
|
||||
host.set_variable(k,ast.literal_eval(v))
|
||||
except:
|
||||
# most likely a string that literal_eval
|
||||
# doesn't like, so just set it
|
||||
host.set_variable(k,v)
|
||||
|
||||
# If there is a hash in the value don't pass it through to ast at ast will split at the hash.
|
||||
if "#" in v:
|
||||
host.set_variable(k, v)
|
||||
else:
|
||||
try:
|
||||
host.set_variable(k,ast.literal_eval(v))
|
||||
# Using explicit exceptions.
|
||||
# Likely a string that literal_eval does not like. We wil then just set it.
|
||||
except ValueError:
|
||||
# For some reason this was thought to be malformed.
|
||||
host.set_variable(k, v)
|
||||
except SyntaxError:
|
||||
# Is this a hash with an equals at the end?
|
||||
host.set_variable(k, v)
|
||||
|
||||
self.groups[active_group_name].add_host(host)
|
||||
|
||||
# [southeast:children]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue