diff --git a/roles/generate_vmid/tasks/main.yml b/roles/generate_vmid/tasks/main.yml index e186f5f..ac388e5 100644 --- a/roles/generate_vmid/tasks/main.yml +++ b/roles/generate_vmid/tasks/main.yml @@ -1,35 +1,20 @@ --- -#- name: Generate and associate VMID to VM -# set_fact : -# lab_nodes : -# "{{ lab_nodes | combine({ item.name: {'vmid': lab_vmid_base + idx_lab_nodes} }, recursive=True) }}" -# loop : "{{ lab_nodes }}" -# loop_control : -# label : "{{ item.name }}" -# index_var : idx_lab_nodes - - -#- name: Debug lab_nodes -# debug : -# var : lab_nodes - - -- name: Generate and associate VMID to VM +- name: Generate and associate VMID to VM (new method) set_fact: - lab_nodes: "{{ lookup('template', 'generate_vmid_lookup.j2') }}" - - -#- name: Debug lab_nodes -# debug : -# var : lab_nodes - - -#- name: Debug lab_nodes again -# debug : -# msg : "{{ item.name }} -> {{ item.vmid }}" -# loop: "{{ lab_nodes }}" -# loop_control: -# label: "{{ item.name }}" + lab_nodes: | + [ + {% for lab_node in lab_nodes %} + { + "name" : "{{ lab_node.name }}", + "vmid" : "{{ lab_vmid_base + (loop.index - 1) }}", + "vm_host" : "{{ lab_node.vm_host | default(__pve_node) }}", + "vm_template_id" : "{{ lab_node.vm_template_id | default(__vm_tmpl_id) }}", + "group" : "{{ lab_node.group | default(__default_inventory_group) }}", + "cores" : "{{ lab_node.cores | default(__lab_cores_default) }}", + "mem" : {{ lab_node.mem | default(__lab_mem_default) }}, + }, + {% endfor %} + ] ...