asking
asking

Reputation: 305

How to Sort Array in Double List Ansible?

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?

Upvotes: 0

Views: 145

Answers (1)

asking
asking

Reputation: 305

this works for me:

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

- name: returned data
  debug:         
    var: data

Upvotes: 1

Related Questions