For loop in Ansible Template

2019-07-27 03:46发布

问题:

I have problem!

I'm using for in template file

{% for vhost in item %}
server = {{vhost}}
{% endfor %}

With items use with_items in file yml ansible

But out out is

server = d
server = o
server = m
server = a
server = i
server = n
server = 1
server = .
server = c
server = o
server = m

I want have output

server = domain1.com

How can i do?

回答1:

You appear to have created a loop inside a loop. with_items in your task is the outer loop. {% for vhost in item %} is the inner loop.

The solution is to only have one loop. Try changing your template to:

server = {{ item }}


标签: ansible