Hi all,
I’ve got a JSON file, web_iam_trust_policy.json:
{
"Version": "2012-10-17",
"Statement":
[
{
"Sid": "",
"Effect": "Allow",
"Principal":
{
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
I’m trying to use it in a lookup:
trust_policy: "{{ lookup('file', 'files/aws/web_iam_trust_policy.json') }}"
However, when the param is loaded it’s being converted into a Python dict and then into a string. Within the module:
trust_policy=dict(type='str’),
...
trust_policy = module.params['trust_policy']
print ‘PARROT’, type(trust_policy), trust_policy
Prints:
PARROT <type ‘str’> u'Version': u'2012-10-17', u'Statement': [{u'Action': u'sts:AssumeRole', u'Sid': u'', u'Effect': u'Allow', u'Principal': {u'Service': u'ec2.amazonaws.com'}}]}
If I leave off the type=‘str’, the file is loaded as a dict:
trust_policy=dict(),
...
trust_policy = module.params['trust_policy']
module.exit_json(changed=True, tp=trust_policy)
changed: [127.0.0.1] => {"changed": true, "tp": {"Statement": [{"Action": "sts:AssumeRole", "Effect": "Allow", "Principal": {"Service": "ec2.amazonaws.com"}, "Sid": ""}], "Version": "2012-10-17"}}
How can I prevent this conversion? I just want the raw file contents. debug msg=“{{ lookup(..) }}” does not display this behavior.
Regards,
-scott