Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

jinja2 - jinja ansible flat array template loop

I'm trying to loop over a simple list of strings & insert each of them into an ansible jinja template, but when looping over the variable in the template file, I get

AnsibleUndefinedVariable: 'item' is undefined

-- vars.yml
services:
  - "service 1"
  - "service 2"

-- main.yml
  win_template:
    with_items: "{{ services }}"

-- jinja template
    (% for item in services %)
    {{ item }}
    (% endfor %)
question from:https://stackoverflow.com/questions/65942219/jinja-ansible-flat-array-template-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK, this turned out to be really simple in the end, no array loops, purely

{{ services|join("
") }}

in the template file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...