Skip to content

Instantly share code, notes, and snippets.

@tjtoml
Last active September 7, 2020 19:35
Show Gist options
  • Save tjtoml/4180d973e2aa9cbb47e0cb5ce973fcbb to your computer and use it in GitHub Desktop.
Save tjtoml/4180d973e2aa9cbb47e0cb5ce973fcbb to your computer and use it in GitHub Desktop.
ansible looping
#path /tmp/test1.txt
test1
test1-foo
test1-bar
3000
#path /tmp/test2.txt
test2
test2-foo
test2-bar
3001
- hosts: all
vars_files: vars.yml
tasks:
name: template
template:
src: src.j2
dest: /tmp/{{ item.name }}.txt
owner: root
group: root
mode: 0777
loop: "{{ sites }}"
{{ item.name }}
{{ item.foo }}
{{ item.bar }}
{{ 3000 + loop_index }}
---
sites:
- name: test1
foo: test1-foo
bar: test2-bar
- name: test2
foo: test2-foo
bar: test2-bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment