Skip to content

Don't sort config. Respect the original order #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pescobar
Copy link

while testing the role I realized if I define this varible:

netplan_conf: |
  network:
    version: {{ netplan_version }}
    renderer: {{ netplan_renderer }}
    ethernets:
      eth0:
        addresses:
        - 10.34.46.100/24
      ens19:
        addresses:
        - 192.168.2.2/24
      ens20:
        addresses:
        - 192.168.3.2/24

I get this config (different order)

network:
  ethernets:
    ens19:
      addresses:
      - 192.168.2.2/24
    ens20:
      addresses:
      - 192.168.3.2/24
    eth0:
      addresses:
      - 10.34.46.100/24
  renderer: networkd
  version: 2

With this PR the generated config respects the same order defined in the ansible var e.g.

#
# Ansible managed
#
---
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
      - 10.34.46.100/24
    ens19:
      addresses:
      - 192.168.2.2/24
    ens20:
      addresses:
      - 192.168.3.2/24

@tersmitten
Copy link
Member

Isn't it a bit tricky to assume "a dict" to be ordered?

And does it affect the behavior of the role?

@pescobar
Copy link
Author

pescobar commented Mar 16, 2023

As far as I know it doesn't affect the behavior of the role, it's just a matter of convenience from an operator point of view.

Personally I like to define physical interfaces at the top and then logical interfaces (e.g. bond and vlans) at the bottom. I also find convenient that the deployed config file is a 1 to 1 copy of the config defined in netplan_conf and avoid sorting it alphabetically by key (as it happens now). This simplifies debugging or updating an existing config, at least for me.

Feel free to discard the PR if you think it's not useful.

thanks for publishing the role :)

@tersmitten
Copy link
Member

tersmitten commented Mar 17, 2023

I understand what you mean, but I'm not sure that if you disable sorting that you'll get the same order every time (in all Python versions). At least time has been an issue with Dict's in Python.

@tersmitten tersmitten added enhancement New feature or request question Further information is requested labels Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants