Replies: 1 comment 1 reply
-
|
The solution turned out to be simple – a custom operation modeled after server.py's @operation()
def reconnect():
def do_reconnect():
host.disconnect()
host.connect()
yield FunctionCommand(do_reconnect, (), {})
step_1()
reconnect()
step_2()(I do not understand what @Fizzadar: IMO this should be added as a stock operation. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Edit: see first comment.
One of my deploy scripts runs two imported deploys,
step_1which assigns a group to the current SSH user, andstep_2, which runs a command that expects given SSH user to be in said group.The first time this deploy runs,
step_2fails, as the newly assigned group isn't taken into account yet in the ongoing SSH session.Note: the workaround I currently use in
step_1is utilizingsgas a wrapper, like so:sg newgroup -c 'command --flag'.While this does work for
step_1's functions, it would not be a feasible solution forstep_2, as this is kept as an individual Python module that must not know about internals ofstep_1.The other workarounds seem clumsy or didn't work.
server.reboot()interrupts other services.server.shell(commands=["kill -HUP $(echo $$)"])doesn't work either, as pyinfra does not attempt a reconnect (Error: executed 0 commands).hostobject'sdisconnect()andconnect()functions apparently didn't yield any logs or effect.What's the suggested solution here? Could we have a
server.reconnect()operation for this use case?Beta Was this translation helpful? Give feedback.
All reactions