Remove any sudo askpass file before issuing a reboot.
This fixes the case where the reboot fails (expected or not) and then we
try to remove the file over a broken SSH session. Fixed by simply removing
any file before issuing the reboot command.
@@ -14,6 +14,7 @@ import six
from six.moves import filterfalse, shlex_quote
from pyinfra.api import FunctionCommand, operation, OperationError, StringCommand
+from pyinfra.api.connectors.util import remove_any_sudo_askpass_file
from pyinfra.api.util import try_int
from pyinfra.facts.server import Which
@@ -56,6 +57,10 @@ def reboot(delay=10, interval=1, reboot_timeout=300, state=None, host=None):
)
'''
+ # Remove this now, before we reboot the server - if the reboot fails (expected or not)
+ # we'll error if we don't clean this up now. Will simply be re-uploaded if needed later.
+ remove_any_sudo_askpass_file(host)
+
yield StringCommand('reboot', success_exit_codes=[0, -1]) # -1 being error/disconnected
def wait_and_reconnect(state, host): # pragma: no cover
