From ed0753ad224f0c65133bd7a63180257eecd9f5e3 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Wed, 8 Jan 2025 10:48:09 +0100 Subject: vault backup: 2025-01-08 10:48:09 --- .../3 resources/ansible/loop-results-prior-loop.md | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .trash/3 resources/ansible/loop-results-prior-loop.md (limited to '.trash/3 resources/ansible/loop-results-prior-loop.md') diff --git a/.trash/3 resources/ansible/loop-results-prior-loop.md b/.trash/3 resources/ansible/loop-results-prior-loop.md new file mode 100644 index 0000000..cbd50a2 --- /dev/null +++ b/.trash/3 resources/ansible/loop-results-prior-loop.md @@ -0,0 +1,30 @@ +```YAML +- name: First loop + loop: {{ blaat }} + register: loooped + ... + +- name: Second loop + loop: {{ loooped.results }} + when: item.skipped is not defined +``` + +this loops over results of prior loop only but does not process any skipped results. + +In case the results array contains another array that we want to loop over, for example when we did a shell command in a loop we can use extract: +``` +- name: Print magic + ansible.builtin.debug: + msg: "{{ ['stdout_lines'] | map('extract', item) }}" + loop: "{{ magic.results }}" +``` + +A cool example of this in practice: +``` +- name: Print blockpull command + ansible.builtin.debug: + msg: "virsh blockpull {{ ['stdout_lines'] | map('extract', item) | list | flatten | join(' ') }}" + loop: "{{ domain_and_disk_paths.results }}" + loop_control: + label: "{{ inventory_hostname }}" +``` \ No newline at end of file -- cgit v1.2.3