Apologies beforehand as this is more of an ansible issue than NetApp Ontap, but I cannot figure out how to calculate a certain value.
let's imagine this scenario, I will have a list of LUN mapping ID:
- 10
- 11
- 12
- 13
If I deleted the LUN with LUN mapping ID = 11, my playbook gives me 14 as the next lun_id value. What I want is for the playbook to have this list
- 10
- 12
- 13
and check if a number is missing, in this case is 11 so the next lun_id would be 11 and not 14 . Same thing if I deleted 11 and 12 the list would be : - 10
- 13
so the next lun_id would 11 and the next run would be 12
There is also the condition that the lun_id should always be > 10.
Here is my current code :
`
-
name: Build LUN Mapping list
when: lun_map_output.msg.num_records | int > 0
block:-
name: Make LUN Mapping list
ansible.builtin.set_fact:
lun_map_list: "{{ lun_map_list | default({}) | combine({ index_lun_map.path: index_lun_map.lun_id }) }}"
loop: "{{ lun_map_output['msg']['records'] }}"
loop_control:
loop_var: index_lun_map -
name: Get Latest LUN Mapping ID
ansible.builtin.set_fact:
lun_map_last_id: "{{ item.value | int }}"
with_items: "{{ lun_map_list | dict2items | sort(attribute='value') }}"
-
-
name: Define LUN Mapping list when none exist
when: lun_map_output.msg.num_records | int == 0
ansible.builtin.set_fact:
lun_map_last_id: 0 -
name: Set calculated LUN ID
ansible.builtin.set_fact:
lun_map_chosen_id: "{{ ( lun_map_last_id | int + 1 ) if ( lun_map_last_id | int != 0 ) else 10 }}"
`
Could you guys let me know how can I achieve this ? Thanks a lot.