Filter items on list based on its index

Viewed 30

I have the following variables:

total_list: [ node1, node2, node5 ]
desired_cluster_size: 2

I need to keep the nth first elements in total_list based on the integer in variable desired_cluster_size. My exepected result is:

desired_list : [ node1, node2 ]

I have no idea where to start to fulfill this requirement.

1 Answers

=> desired_list: "{{ total_list[:desired_cluster_size|int] }}" –

thanks this helped Zeitounator

Related