# Printing from a list

**URL:** <https://forum.ansible.com/t/printing-from-a-list/25711>\
**Category:** Ansible Project\
**Created:** [October 10, 2017, 6:04am UTC](https://forum.ansible.com/t/printing-from-a-list/25711 "2017-10-10T06:04:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanpassel7](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@alanpassel7](https://forum.ansible.com/u/alanpassel7)\
**Post date:** [October 10, 2017, 6:04am UTC](https://forum.ansible.com/t/printing-from-a-list/25711/1 "2017-10-10T06:04:34Z")

</div>

Sorry if that’s a terrible subject - I couldn’t think of another way to summarize my issue.

What I’m trying to do is create a template that will iterate over a list, to create a few files with different names, with the same variable also being printed inside of those files.

The way I am attempting to do this is with a template and a vars file. The task looks like so:

`

- name: Copy template  
template:  
src: template.yml.j2  
dest: /tmp/template.yml  
`

With the vars/main.yml looking like this:

`  
variable:

- variable-to-print  
`

When I run the playbook, it gives me a file named [u’variable-to-print’], and each time the variable is supposed to be substituted inside the file, it’s printed the same way, as [u’variable-to-print’], instead of as variable-to-print.

If I do it so that there’s no yaml list in the vars/main.yml, like so:

`variable: variable-to-print`

Then it works just fine, but that kind of defeats the purpose for me.

Can anyone recommend how I might get it to give me the variable substitution that I’m looking for, without the brackets, u, and single quotes?

Thanks,

- ap

---

<div class="post-metadata">

**Author:** ![doug](https://avatars.discourse-cdn.com/v4/letter/d/dbc845/32.png) [@doug](https://forum.ansible.com/u/doug)\
**Post date:** [October 10, 2017, 12:07pm UTC](https://forum.ansible.com/t/printing-from-a-list/25711/2 "2017-10-10T12:07:39Z")

</div>

You need to seek documentation on looping using “with\_items.”

---

<div class="post-metadata">

**Author:** ![alanpassel7](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@alanpassel7](https://forum.ansible.com/u/alanpassel7)\
**Post date:** [October 10, 2017, 10:51pm UTC](https://forum.ansible.com/t/printing-from-a-list/25711/3 "2017-10-10T22:51:53Z")

</div>

I don’t see how that’s applicable to the variable expansion within the template. As far as the file name, in this case it looks like it’s better to just dump it all into one file, so now variable expansion inside the template is the only issue, but looping with with\_items is, as I see it, something else entirely.

---

<div class="post-metadata">

**Author:** ![alanpassel7](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@alanpassel7](https://forum.ansible.com/u/alanpassel7)\
**Post date:** [October 10, 2017, 11:48pm UTC](https://forum.ansible.com/t/printing-from-a-list/25711/4 "2017-10-10T23:48:29Z")

</div>

Nevermind, figured it out. Thanks folks.
