Created
July 23, 2018 16:16
-
-
Save VerosK/25a4488ed59064499c5c27a111d8e3fe to your computer and use it in GitHub Desktop.
Sort dict in Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
vars: | |
images: | |
- name: first | |
date: 001 | |
- name: second | |
date: 002 | |
- name: fourth | |
date: 004 | |
- name: third | |
date: 003 | |
tasks: | |
- set_fact: | |
sorted: '{{ images|sort(attribute="date") }}' | |
reversed: '{{ images|sort(attribute="date", reverse=True) }}' | |
- debug: | |
var: sorted | |
- name: Show items ordered | |
debug: | |
msg: '{{ item.name }}' | |
with_items: "{{ sorted }}" | |
- name: Show items ordered reverse | |
debug: | |
msg: '{{ item.name }}' | |
with_items: "{{ reversed }}" | |
- name: Show items ordered except first one | |
debug: | |
msg: '{{ item.name }}' | |
with_items: "{{ sorted[1:] }}" | |
- name: Show items ordered except last one | |
debug: | |
msg: '{{ item.name }}' | |
with_items: "{{ sorted[:-1] }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment