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.
Salt custom grain to override os_family grain to ensure Rocky Linux is as part of the RedHat OS family.
#!/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 /svc/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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment