From ba4c2ebeac9ee801bfedff05f504c71da0dd2bc2 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 10 Dec 2018 09:55:18 -0500 Subject: [PATCH] ensure ssh retry respects no log (#49569) --- .../fragments/avoid_ssh_retry_discolsures.yml | 2 ++ lib/ansible/plugins/connection/ssh.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/avoid_ssh_retry_discolsures.yml diff --git a/changelogs/fragments/avoid_ssh_retry_discolsures.yml b/changelogs/fragments/avoid_ssh_retry_discolsures.yml new file mode 100644 index 00000000000..03d3689eba5 --- /dev/null +++ b/changelogs/fragments/avoid_ssh_retry_discolsures.yml @@ -0,0 +1,2 @@ +bugfixes: + - now no log is being respected on retry and high verbosity diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 8f5f2933c7a..813220d460e 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -332,11 +332,14 @@ def _ssh_retry(func): try: try: return_tuple = func(self, *args, **kwargs) - display.vvv(return_tuple, host=self.host) + if self._play_context.no_log: + display.vvv('rc=%s, stdout & stderr censored due to no log' % return_tuple[0], host=self.host) + else: + display.vvv(return_tuple, host=self.host) # 0 = success # 1-254 = remote command return code # 255 could be a failure from the ssh command itself - except (AnsibleControlPersistBrokenPipeError) as e: + except (AnsibleControlPersistBrokenPipeError): # Retry one more time because of the ControlPersist broken pipe (see #16731) cmd = args[0] if self._play_context.password and isinstance(cmd, list): @@ -354,8 +357,12 @@ def _ssh_retry(func): break if SSH_ERROR: - raise AnsibleConnectionFailure("Failed to connect to the host via ssh: %s" - % to_native(return_tuple[2])) + msg = "Failed to connect to the host via ssh: " + if self._play_context.no_log: + msg += '' + else: + msg += to_native(return_tuple[2]) + raise AnsibleConnectionFailure(msg) break