Skip to content

preserve the order of dictionaries when applying changes #29

@richm

Description

@richm

For example, https://github.com/linux-system-roles/.github/blob/main/inventory/host_vars/network.yml#L9

  extra_vars:
    test_playbook: tests_default.yml
    network_provider: nm

when this was applied to the role, the order of the keys was not preserved, leading to a spurious change: https://github.com/linux-system-roles/network/pull/603/files#diff-20d1610925e550787a5f9dd9061f1e8ce9cee711b8f8165cd066b151179a9ba9L4

extra_vars:
-  test_playbook: tests_default.yml
  network_provider: nm
+  test_playbook: tests_default.yml

While new version is still semantically equivalent to the old version, it is confusing to reviewers. We should attempt to reduce that confusion by preserving the order of the elements e.g. is there some way to make Ansible/Jinja use an OrderedDict when parsing/writing out the elements? If there isn't, then maybe there is some way to sort the keys - the first time we do this we may see a large change, but subsequent changes should be much smaller.

@spetrosi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions