# How to use policy\_document in iam\_policy module?

**URL:** <https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [August 20, 2015, 5:49pm UTC](https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071 "2015-08-20T17:49:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user90](https://avatars.discourse-cdn.com/v4/letter/u/df788c/32.png) [@user90](https://forum.ansible.com/u/user90)\
**Post date:** [August 20, 2015, 5:49pm UTC](https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071/1 "2015-08-20T17:49:39Z")

</div>

Hello, can you provide me example how to use policy\_document from iam\_policy module?  
policy\_document: “policy.json.j2” (In policy.json.j2 I store json, copied from AWS policy generator and want to save formatting for readability, policy.json.j2 stored in templates/ folder)

I’v got an exception:  
No such file or directory: ‘policy.json.j2’

---

<div class="post-metadata">

**Author:** ![kevin\_wessel](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kevin\_wessel](https://forum.ansible.com/u/kevin_wessel)\
**Post date:** [August 20, 2015, 10:32pm UTC](https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071/2 "2015-08-20T22:32:58Z")

</div>

Hi Сергей Жеревчук,

I usually pass my policy as a json file which I store under the files directory, please see my directory structure below:

files/  
policies/  
policy.json

main.yml

In my playbook I reference the file like so:

- name: Create and attach IAM policy to IAM role  
iam\_policy:  
iam\_type: role  
aws\_access\_key: “{{ aws\_access\_key\_id }}”  
aws\_secret\_key: “{{ aws\_secret\_access\_key }}”  
iam\_name: iam-role  
policy\_name: new-policy-name  
state: present  
policy\_document: “files/policies/linux-standard.json”

This works for me 🙂

I hope that helps.

---

<div class="post-metadata">

**Author:** ![user90](https://avatars.discourse-cdn.com/v4/letter/u/df788c/32.png) [@user90](https://forum.ansible.com/u/user90)\
**Post date:** [August 21, 2015, 9:07am UTC](https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071/3 "2015-08-21T09:07:03Z")

</div>

Hi, kevin. It’s work for me too. Also I realized, that I can save rendered template in tmp directory and then use policy\_document. Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_Weinrich](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Michael\_Weinrich](https://forum.ansible.com/u/Michael_Weinrich)\
**Post date:** [August 21, 2015, 9:53pm UTC](https://forum.ansible.com/t/how-to-use-policy-document-in-iam-policy-module/19071/4 "2015-08-21T21:53:50Z")

</div>

You can also use policy\_json to pass the policy directly as string. I added this a while ago because I had the need to use a real template as policy, not a static file.
