File “/home/ubuntu/ansible/lib/ansible/utils/template.py”, line 222, in varReplace
replacement = “,”.join(replacement)
TypeError: sequence item 0: expected string, dict found
So I hacked lib/ansible/utils/template.py:
if expand_lists and isinstance(replacement, (list, tuple)):
if isinstance(replacement, (list)):
parts =
for item in replacement:
if item is dict:
pass
else:
parts.append(item)
replacement = parts.str()
else:
replacement = “,”.join(replacement)
Which was enough to let me move on… but I still am dealing with a string instead of a list of dictionaries like I was hoping for. So I wound up using ast.literal_eval.
So my question is, is there a way to pass a variable (which is a list) without it getting converted to a string?
And yes, that will call your module multiple times.
You can't pass complex variables to modules -- that's coming super
soon now (this weekend) - although even then the module has to be
coded to do something with that data.
So I hacked lib/ansible/utils/template.py:
if expand_lists and isinstance(replacement, (list, tuple)):
if isinstance(replacement, (list)):
parts =
for item in replacement:
if item is dict:
pass
else:
parts.append(item)
replacement = parts.__str__()
else:
replacement = ",".join(replacement)
Which was enough to let me move on... but I still am dealing with a string
instead of a list of dictionaries like I was hoping for. So I wound up using
ast.literal_eval.
So my question is, is there a way to pass a variable (which is a list)
without it getting converted to a string?
Of course I started coding right before your merges… that’s life.
The ec2_vol module will work, though not as I had intended. I will now be provisioning the volumes in my setup playbook, instead of my provisioning playbook.
To provision, I have different values for instances and volumes based on whether this is dev, staging or prod, but it is basically something like: