Skip to content

Instantly share code, notes, and snippets.

@gorshunovr
Created October 2, 2018 12:33
Show Gist options
  • Save gorshunovr/cfe1232d03d940fb8ed5095d3318fb38 to your computer and use it in GitHub Desktop.
Save gorshunovr/cfe1232d03d940fb8ed5095d3318fb38 to your computer and use it in GitHub Desktop.
---
- hosts: localhost
gather_facts: no
tasks:
- name: "loop through list"
debug:
msg: "An item: {{ item }}"
with_items:
- 1
- 2
- 3
- name: Create the list
set_fact:
my_list:
- "One fish"
- "Two fish"
- "Red fish"
- "Blue fish"
- name: "loop through list - flat 1"
debug:
msg: "Flat items: {{ my_list | join(' --option ') }}"
- name: "set_fact"
set_fact:
my_list: "{{ my_list | map('regex_replace', '^(.*)$', 'PREFIX \\1 SUFFIX') | list }}"
- name: "loop through list - flat 2"
debug:
msg: "Flat items: {{ my_list | join(' ') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment