Skip to content

Instantly share code, notes, and snippets.

@ixs
Last active July 4, 2021 12:49
Show Gist options
  • Save ixs/d91c71e679ce3d459a68a3f566f11dfd to your computer and use it in GitHub Desktop.
Save ixs/d91c71e679ce3d459a68a3f566f11dfd to your computer and use it in GitHub Desktop.

Revisions

  1. ixs revised this gist Jul 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rocky_os_family.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # Similar functionality was added in https://github.com/saltstack/salt/pull/59682
    # but has not been released yet.
    #
    # To install, drop this code into /src/salt/_grains/ and run
    # To install, drop this code into /svc/salt/_grains/ and run
    # `salt '*' saltutil.sync_all`

    _OS_FAMILY_MAP = {"Rocky Linux": "RedHat"}
  2. ixs created this gist Jul 4, 2021.
    28 changes: 28 additions & 0 deletions rocky_os_family.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env python3

    # Override os_family grain to ensure Rocky Linux is seen
    # as part of the RedHat OS family.
    #
    # Similar functionality was added in https://github.com/saltstack/salt/pull/59682
    # but has not been released yet.
    #
    # To install, drop this code into /src/salt/_grains/ and run
    # `salt '*' saltutil.sync_all`

    _OS_FAMILY_MAP = {"Rocky Linux": "RedHat"}

    def main():
    os_data = {}
    with open("/etc/os-release", "r") as f:
    for line in f.readlines():
    try:
    k, v = line.strip().split("=", 1)
    os_data.update({k: v.replace('"', '')})
    except ValueError:
    continue

    if os_data["NAME"] in _OS_FAMILY_MAP:
    return {"os_family": _OS_FAMILY_MAP[os_data["NAME"]]}

    if __name__ == "__main__":
    print(main())