From ce19e3b21c9b4bf115a5c3a71950ab12f2914d6c Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Tue, 28 Jan 2025 23:25:42 +0100 Subject: [PATCH] chore(ansible): get first and last elements in lists --- snippets/ansible/tasks.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 7455c25..a591cba 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -113,9 +113,12 @@ dbs_list: ['primary', 'sales'] ansible.builtin.set_fact: list_without_items: "{{ dbs_list | difference(['template0','template1','postgres','rdsadmin']) }}" - - name: Get a random element + - name: Get elements ansible.builtin.set_fact: random_item: "{{ ['a','b','c'] | random }}" + last_item_array_mode: "{{ ['a','b','c'][-1] }}" + last_item_filter: "{{ ['a','b','c'] | last }}" + first_item_filter: "{{ ['a','b','c'] | first }}" - name: Sort dict elements in lists by attribute tags: order_by vars: