Skip to content

Commit 3188ad8

Browse files
committed
facts: server.Groups: go through libnss
This will respect the settings in nsswitch.conf but requires that 'getent' is available.
1 parent 935ce07 commit 3188ad8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pyinfra/facts/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,14 @@ class Groups(FactBase[List[str]]):
391391
"""
392392

393393
def command(self):
394-
return "cat /etc/group"
394+
# getent will return the same output as `cat /etc/groups` but will
395+
# respect nsswitch.conf settings, e.g. for using LDAP as additional source
396+
# Note, that LDAP e.g. using sssd might be configured to not enumerate
397+
# all groups / users, in which case only the local groups will be returned
398+
return "getent group"
399+
400+
def requires_command(self) -> str:
401+
return "getent"
395402

396403
default = list
397404

tests/facts/server.Groups/groups.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"command": "cat /etc/group",
2+
"command": "getent group",
3+
"requires_command": "getent",
34
"output": [
45
"lpadmin:x:114:vagrant",
56
"sambashare:x:115:vagrant",

0 commit comments

Comments
 (0)