Skip to content

Commit ce73876

Browse files
aaron-riactFizzadar
authored andcommitted
operations/server.user: make append work
1 parent 079c23e commit ce73876

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pyinfra/operations/server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,13 @@ def user(
939939
args.append("-g {0}".format(group))
940940

941941
# Check secondary groups, if defined
942-
if groups and set(existing_user["groups"]) != set(groups):
942+
if groups:
943943
if append:
944-
args.append("-a")
945-
args.append("-G {0}".format(",".join(groups)))
944+
if not set(groups).issubset(existing_user["groups"]):
945+
args.append("-a")
946+
args.append("-G {0}".format(",".join(groups)))
947+
elif set(existing_user["groups"]) != set(groups):
948+
args.append("-G {0}".format(",".join(groups)))
946949

947950
if comment and existing_user["comment"] != comment:
948951
args.append("-c '{0}'".format(comment))
@@ -965,7 +968,10 @@ def user(
965968
if group:
966969
existing_user["group"] = group
967970
if groups:
968-
existing_user["groups"] = groups
971+
if append:
972+
existing_user["groups"] += groups
973+
else:
974+
existing_user["groups"] = groups
969975
if password:
970976
existing_user["password"] = password
971977

0 commit comments

Comments
 (0)