Tuesday, July 26, 2022

[FIXED] How to Sort Array in Double List Ansible?

Issue

I have a double list like this:

dataset:
    - [dataone, A]
    - [datatwo, C]
    - [dataa, B]
    - [dataa, C]
    - [dataa, B]

I want to sort the first array and have the second array stick with the first one like this:

data:
    - [dataa, B]
    - [dataa, C]
    - [dataa, B]
    - [dataone, A]
    - [datatwo, C]

Any duplicate data needs to still show (the arrangement of second array value doesnt matter)

What should I do?


Solution

this works for me:

- set_fact:
    data: "{{ dataset | sort | list }}"

- name: returned data
  debug:         
    var: data


Answered By - asking
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.