pyinfra-dev / pyinfra-dev/pyinfra

Enhance OperationMeta to give more info on changes, depending on Operation

Open
#705 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API spec
Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Description

Is your feature request related to a problem? Please describe

Operations return an object with a changed attribute that is set to True whenever any changes have been performed on the remote host. It would be very good to have a bit more information available as to what changed, depending on the operation.

Example:

I create users like this:

for user in host.data.users:
    created_user = server.user(
        name=f"Create user {user}",
        user=user,
        groups=('sudo', 'docker'),
        public_keys=[f'files/pub_keys/{user}.authorized_keys'],
        sudo=True,
    )

    if created_user.changed:
        server.shell(
            name=f"Force user {user} on first login to set password",
            commands=[f"passwd -d {user}", f"passwd -e {user}"],
            sudo=True,
        )

The idea is that a newly created user is forced to change their password on first login. What I don't want, however, is having the if-branch executed, just because e.g. an existing user's groups or public_keys changed. But changed is True, no matter what changed, and I would need to look deeper into e.g. changed_user.get_masked_value() to see if a useradd -d … command is present. I didn't get it to work so far, and would like to have functionality like that exposed directly, e.g. by having operations that can give additional info like this return a subclass of OperationMeta with additional attributes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading OperationMeta and the get_masked_value behavior, then trace how operation results expose the changed attribute. Define what operation-specific change information must be available for the user example, and consider how completion can be verified without relying on the current masked value inspection.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.