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

SystemdStatus fact result data selection/restriction #1059

Open
hjoukl opened this issue Jan 12, 2024 · 2 comments
Open

SystemdStatus fact result data selection/restriction #1059

hjoukl opened this issue Jan 12, 2024 · 2 comments
Labels
Facts Issues with facts.

Comments

@hjoukl
Copy link

hjoukl commented Jan 12, 2024

Is your feature request related to a problem? Please describe

I wanted to select only specific information from the systemd.SystemdStatus fact result (dictionary).
I.e. get only info on a subset of systemd-Services, by service name.

Describe the solution you'd like

SystemdStatus returns a dictionary {server: {service_name: service_active, ...}}, e.g.:

--> Fact data for: systemd.SystemdStatus
{
    "myserver": {
        "lvm2-lvmetad.service": true,
        "goferd.service": true,
        "systemd-reboot.service": false,
        "systemd-journald.service": true,
        ...

}

I'd like to only show information for a selected subset of services. Since the ad-hoc facts command invocation allows for arguments for the fact gathering, how about to add some mechanism to do that, e.g.

# Possibility 1: restrict service names to gather info about with an additional fact arg e.g.
pyinfra myserver fact systemd.SystemdStatus service_names="sshd-keygen.service, sendmail.service"
# Or maybe list each name separately(?)
pyinfra myserver fact systemd.SystemdStatus service_name="sshd-keygen.service" service_name="sendmail.service"

# Possibility 2: general possibility to restrict dictionary fact return values.
# This could then also work for other facts with dict results.
pyinfra myserver fact systemd.SystemdStatus --select-result-keys="sshd-keygen.service, sendmail.service"
# Or maybe allow for a regex selection - might be overkill(?)
pyinfra myserver fact systemd.SystemdStatus --select-result-keys="(sshd-keygen|sendmail)\.service"

Variations possible, example arg names debatable, of course.

I'm aware there's other possibilities to get at the information already, like

pyinfra myserver exec -- systemctl status goferd.service
pyinfra myserver -- systemctl show goferd.service --property=StatusErrno

Still, it feels like this would complement existing functionality nicely/naturally.

Best regards
Holger

@Fizzadar
Copy link
Member

Hi Holger! This is a great idea, I’ve actually implemented just this for v3 here: 0db3632

So you should be able to pass services list to the existing fact to reduce the services queried!

@Fizzadar Fizzadar added the Facts Issues with facts. label Mar 13, 2024
@hjoukl
Copy link
Author

hjoukl commented Mar 13, 2024

Great, looking forward to v3! pyinfra is fabulous. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Facts Issues with facts.
Projects
None yet
Development

No branches or pull requests

2 participants