Skip to content

Commit 4f13abf

Browse files
holsercursoragent
authored andcommitted
[sushy_emulator] Replace regex with join filter for VM instance list
- Replace complex Jinja2 for-loop with idiomatic filter chain (dict2items | selectattr | map | list) - Remove regex_replace in favor of list in template - Keep variable as list for loop/index access in tasks Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Sergii Golovatiuk <sgolovat@redhat.com>
1 parent 82b1ab0 commit 4f13abf

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

roles/sushy_emulator/tasks/collect_details.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@
9797
- name: Generate list of filtered VMs
9898
vars:
9999
_matching_vms: >-
100-
{% set matching_vms = [] -%}
101-
{% for host, uuid in cifmw_libvirt_manager_uuids.items() -%}
102-
{% if host | regex_search(cifmw_sushy_emulator_vm_prefix_filter | default('') + '.*') -%}
103-
{% set _ = matching_vms.append(uuid) -%}
104-
{% endif -%}
105-
{% endfor -%}
106-
{{ matching_vms }}
100+
{{
101+
cifmw_libvirt_manager_uuids |
102+
dict2items |
103+
selectattr('key', 'match', cifmw_sushy_emulator_vm_prefix_filter | default('') ~ '.*') |
104+
map(attribute='value') |
105+
list
106+
}}
107107
ansible.builtin.set_fact:
108-
_cifmw_sushy_emulator_instances: "{{ _matching_vms | regex_replace('\n(?!.*\n)', ', ')}}"
108+
_cifmw_sushy_emulator_instances: "{{ _matching_vms }}"
109109
when:
110110
- _matching_vms | length > 0
111111

0 commit comments

Comments
 (0)