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

Installing a package may create a user but not update the fact #987

Closed
link2xt opened this issue May 31, 2023 · 3 comments
Closed

Installing a package may create a user but not update the fact #987

link2xt opened this issue May 31, 2023 · 3 comments
Labels
bug Label for all kind of bugs.

Comments

@link2xt
Copy link
Contributor

link2xt commented May 31, 2023

Describe the bug

Operation server.user depends on the facts about the user to choose between using useradd and usermod. If the facts about users say that user does not exist, but in fact the user exists, pyinfra effectively does nothing.

To Reproduce

Create the following deploy.py file:

from pyinfra.operations import apt, server

apt.packages(name="Install postfix", packages=["postfix"], update=True)
server.group(name="Create group foo", group="foo", system=True)
server.user(
    name="Add user postfix to group foo", user="postfix", group="foo", system=True
)

Run pyinfra -vvvv --ssh-user root example.org deploy.py, where example.org is a freshly installed Ubuntu 22.04 VM.

Expected behavior

I expect that postfix package is installed and then pyinfra adds the user postfix to the group foo.
Instead, pyinfra does not add the user to the group, but checks that user exists and does not execute useradd.

--> Starting operation: Add user postfix to group foo 
[example.org] >>> sh -c 'grep '"'"'^postfix:'"'"' /etc/passwd || useradd -d /home/postfix -g foo -r postfix'
[example.org] postfix:x:114:120::/var/spool/postfix:/usr/sbin/nologin
[example.org] >>> sh -c 'mkdir -p /home/postfix'
[example.org] >>> sh -c 'chown postfix:foo /home/postfix'
[example.org] Success

It should instead run usermod.

The solution would be to fix apt to update the facts about the users to include the information about the user postfix added by the post-install script.

@link2xt link2xt added the bug Label for all kind of bugs. label May 31, 2023
@link2xt
Copy link
Contributor Author

link2xt commented May 31, 2023

My current workaround for this is creating all the groups and users at the beginning of the deploy, but this may not be possible in a structured deploy with functions calling each other.

@Fizzadar
Copy link
Member

Another unfortunate example of operation side effects impacting each other (#805), I am working on a new approach that may resolve these once and for all 🤞!

@Fizzadar Fizzadar added this to the v3 milestone Nov 25, 2023
@Fizzadar Fizzadar removed this from the v3 milestone Jan 14, 2024
@Fizzadar
Copy link
Member

Fizzadar commented Feb 3, 2024

v3 fixes this, now that the first beta is out I’ll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label for all kind of bugs.
Projects
None yet
Development

No branches or pull requests

2 participants