Sort ansible_facts.packages|dict2items

83 views
Skip to first unread message

akash...@gmail.com

unread,
Jun 22, 2021, 1:25:10 PM6/22/21
to Ansible Project
Hi All, 

Request your help on how to sort a dict2item "{{ ansible_facts.packages|dict2items }}"

Dick Visser

unread,
Jun 22, 2021, 2:45:12 PM6/22/21
to ansible...@googlegroups.com
Request an example for such a data structure

On Tue, 22 Jun 2021 at 19:25, akash...@gmail.com <akash...@gmail.com> wrote:
>
> Hi All,
>
> Request your help on how to sort a dict2item "{{ ansible_facts.packages|dict2items }}"
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/07e61cac-a343-4f01-9ee0-5a4c6cd11907n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

akash...@gmail.com

unread,
Jun 23, 2021, 1:18:20 AM6/23/21
to Ansible Project
As you know that the module "ansible_facts.packages" collects all the rpm packages installed on a host , so we need to sort those packages in alphabetical order eg:  aaa_base,  SuSEfirewall2 .. 
        "SuSEfirewall2": [
            {
                "arch": "noarch",
                "epoch": null,
                "name": "SuSEfirewall2",
                "release": "1.33",
                "source": "rpm",
                "version": "3.6.378"
            }
        ],
        "aaa_base": [
            {
                "arch": "x86_64",
                "epoch": null,
                "name": "aaa_base",
                "release": "3.42.1",
                "source": "rpm",
                "version": "84.87+git20180409.04c9dae"
            }
        ],


akash...@gmail.com

unread,
Jun 23, 2021, 1:20:00 AM6/23/21
to Ansible Project
  - name: Gather the package facts
    package_facts:
      manager: auto

Dick Visser

unread,
Jun 23, 2021, 3:15:12 AM6/23/21
to ansible...@googlegroups.com
Those facts are already sorted.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/54d88f4d-c765-49ee-af74-4bb6d3b4b3b3n%40googlegroups.com.

akash...@gmail.com

unread,
Jun 23, 2021, 4:55:29 AM6/23/21
to Ansible Project
When it is converted to dict2items the sorting is gone

Dick Visser

unread,
Jun 23, 2021, 6:00:07 AM6/23/21
to ansible...@googlegroups.com
On Wed, 23 Jun 2021 at 10:55, akash...@gmail.com <akash...@gmail.com> wrote:
>
> When it is converted to dict2items the sorting is gone

Are you sure?
What makes you think that?
Please post some evidence in case you do.
Reply all
Reply to author
Forward
0 new messages