Skip to content

Commit b110388

Browse files
authored
Add OsRelease fact to retrieve release information from /etc/os-release (#1222)
* Add OsRelease fact to retrieve release information from /etc/os-release * Improve value parsing and loop condition
1 parent fb01bea commit b110388

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pyinfra/facts/server.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,36 @@ def process(self, output):
307307
return items
308308

309309

310+
class OsRelease(FactBase):
311+
"""
312+
Returns a dictionary of release information stored in ``/etc/os-release``.
313+
314+
.. code:: python
315+
316+
{
317+
"name": "EndeavourOS",
318+
"pretty_name": "EndeavourOS",
319+
"id": "endeavouros",
320+
"id_like": "arch",
321+
"build_id": "2024.06.25",
322+
...
323+
}
324+
"""
325+
326+
def command(self):
327+
return "cat /etc/os-release"
328+
329+
def process(self, output):
330+
items = {}
331+
332+
for line in output:
333+
if "=" in line:
334+
key, value = line.split("=", 1)
335+
items[key.strip().lower()] = value.strip().strip('"')
336+
337+
return items
338+
339+
310340
class Sysctl(FactBase):
311341
"""
312342
Returns a dictionary of sysctl settings and values.

0 commit comments

Comments
 (0)