Printing from a list

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

You need to seek documentation on looping using “with_items.”

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.

Nevermind, figured it out. Thanks folks.