Last active
July 4, 2021 12:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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