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

Reboot - Fix errors when using Paramiko connection #49002

Merged
merged 2 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/ansible/plugins/action/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,24 @@ def do_until_success_or_timeout(self, action, reboot_timeout, action_desc):
display.debug('%s: %s success' % (self._task.action, action_desc))
return
except Exception as e:
if isinstance(e, AnsibleConnectionFailure):
try:
self._connection.reset()
except AnsibleConnectionFailure:
pass
# Use exponential backoff with a max timout, plus a little bit of randomness
random_int = random.randint(0, 1000) / 1000
fail_sleep = 2 ** fail_count + random_int
if fail_sleep > max_fail_sleep:

fail_sleep = max_fail_sleep + random_int
if action_desc:
try:
error = to_text(e).splitlines()[-1]
except TypeError as e:
error = to_text(e)
display.debug("{0}: {1} fail '{2}', retrying in {3:.4} seconds...".format(self._task.action, action_desc,
to_text(e).splitlines()[-1], fail_sleep))
error, fail_sleep))
fail_count += 1
time.sleep(fail_sleep)

Expand Down
7 changes: 6 additions & 1 deletion lib/ansible/plugins/connection/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ def _save_ssh_host_keys(self, filename):

f.close()

def reset(self):
self.close()
self._connect()

def close(self):
''' terminate the connection '''

Expand Down Expand Up @@ -585,11 +589,12 @@ def close(self):

os.rename(tmp_keyfile.name, self.keyfile)

except:
except Exception:

# unable to save keys, including scenario when key was invalid
# and caught earlier
traceback.print_exc()
fcntl.lockf(KEY_LOCK, fcntl.LOCK_UN)

self.ssh.close()
self._connected = False