Skip to content

Instantly share code, notes, and snippets.

@dimaskiddo
Last active December 15, 2021 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimaskiddo/4fae097e4852f9b62b5ad8f07f51bc57 to your computer and use it in GitHub Desktop.
Save dimaskiddo/4fae097e4852f9b62b5ad8f07f51bc57 to your computer and use it in GitHub Desktop.
Ansible Snippet
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: "Create ListX"
set_fact:
listX:
- name: "Dwi"
command: "X"
- name: "Budi"
command: "Y"
- name: "Debug ListX"
debug:
msg: '{{ listX }}'
- name: "Try To Do Something"
shell: "echo {{ clevel.name }}"
loop: '{{ listX | flatten(levels=1) }}'
loop_control:
loop_var: clevel
register: output
- name: "Debug All Output"
debug:
msg: '{{ output.results }}'
- name: "Debug Spesific Output in Loop"
debug:
msg: '{{ item.cmd }}'
loop: '{{ output.results | flatten(levels=1) }}'
- name: "Rebuild ListX as ListY"
vars:
listY: []
set_fact:
listY: '{{ listY + [ { "name":item.clevel.name, "command":item.cmd } ] }}'
loop: '{{ output.results | flatten(levels=1) }}'
- name: "Debug ListY"
debug:
msg: '{{ listY }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment