More tweaks to logic for caching ssh host key

This commit is contained in:
Lance Edgar 2020-10-09 16:38:19 -05:00
parent 8c08412d7b
commit f5a7f80fd4

View file

@ -49,16 +49,16 @@ def cache_host_key(c, host, port=None, user=None, **kwargs):
# basic command failed, but in some cases that is simply b/c normal # basic command failed, but in some cases that is simply b/c normal
# commands are not allowed, although the ssh connection itself was # commands are not allowed, although the ssh connection itself was
# established okay. here we check for that situation. # established okay. here we check for that situation.
if result.stderr.strip() != "Disallowed command": if "Disallowed command" not in result.stderr:
# okay then we now think that the ssh connection itself was not # okay then we now think that the ssh connection itself was not
# made, which presumably means we *do* need to cache the host key, # made, which presumably means we *do* need to cache the host key,
# so try that now # so try that now
cmd = 'ssh -o StrictHostKeyChecking=no {} {} whoami'.format(port, host) cmd = 'ssh -o StrictHostKeyChecking=no {} {} whoami'.format(port, host)
if user: if user:
c.sudo(cmd, user=None if user == 'root' else user) c.sudo(cmd, user=None if user == 'root' else user, warn=True)
else: else:
c.run(cmd) c.run(cmd, warn=True)
def restart(c): def restart(c):