Skip to content

Instantly share code, notes, and snippets.

@mwhahaha
Created August 15, 2018 23:15
Show Gist options
  • Save mwhahaha/a23764047d85d50fb0b66e412ac90046 to your computer and use it in GitHub Desktop.
Save mwhahaha/a23764047d85d50fb0b66e412ac90046 to your computer and use it in GitHub Desktop.
ansible array appending with set_fact
---
- name: looping
shell: >
echo "{{ loop_input }}"
register: foo
- set_fact:
loop_var: []
when: loop_var is not defined
- set_fact:
loop_var: "{{ loop_var }} + {{ [ foo.stdout ] }}"
- debug:
var: loop_var
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: testing loops
include: loop.yml loop_input={{ item }}
with_items:
- 'foo'
- 'bar'
- 'baz'
- debug:
var: loop_var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment