Last active
December 15, 2021 01:14
-
-
Save dimaskiddo/4fae097e4852f9b62b5ad8f07f51bc57 to your computer and use it in GitHub Desktop.
Ansible Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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