Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query all usernames and group names #711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CarstenGrohmann
Copy link
Contributor

@CarstenGrohmann CarstenGrohmann commented Jun 27, 2023

We need some functionality to query all user names as well as all group names. I implemented in two functions:

  • query all (local and remove) users and groups with getent passwd resp. getent group
  • query local users and groups with cat /etc/passwd resp. cat /etc/group

Small tests of all functions are also part of this pull request.

What do you think about such functionality?

@philpep philpep added feature enhancement This issue/PR relates to a feature request. and removed feature labels Aug 24, 2023
"""
all_users = [
line.split(":")[0]
for line in self.check_output("getent passwd").splitlines()
Copy link
Contributor

@martinhoyer martinhoyer Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use pwd?

import pwd
all_users = [pw.pw_name for pw in pwd.getpwall()]

(same with grp for groups)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is not possible because testinfra only executes Unix commands on the remote host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants