# outputting dictionary variables using copy module not working

**URL:** <https://forum.ansible.com/t/outputting-dictionary-variables-using-copy-module-not-working/25733>\
**Category:** Ansible Project\
**Created:** [October 12, 2017, 12:00pm UTC](https://forum.ansible.com/t/outputting-dictionary-variables-using-copy-module-not-working/25733 "2017-10-12T12:00:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [October 12, 2017, 12:00pm UTC](https://forum.ansible.com/t/outputting-dictionary-variables-using-copy-module-not-working/25733/1 "2017-10-12T12:00:47Z")

</div>

Hi,

I am running ansible on centos 7.4.1708 . Not sure what I am doing wrong but the dictionary variables are not completely written by the copy module.

Here is my complete YAML file :

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 12, 2017, 1:29pm UTC](https://forum.ansible.com/t/outputting-dictionary-variables-using-copy-module-not-working/25733/2 "2017-10-12T13:29:57Z")

</div>

Because of the with\_dict the task will run 3 times, one for each item in var\_dict1.  
Only the last will stick since the file will be overwritten.

Do this instead  
&nbsp;&nbsp;&nbsp;- name: Copy the contents of var\_dict1 to output1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for key, value in var\_dict1.iteritems() %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ key }} {{ value }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "/usershome/output1"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run\_once: yes

---

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [October 12, 2017, 2:10pm UTC](https://forum.ansible.com/t/outputting-dictionary-variables-using-copy-module-not-working/25733/3 "2017-10-12T14:10:20Z")

</div>

Hi Kai,

Thanks that worked. Did not know about iteritems until now.

Regards,  
Abey
