From 91f67ac37a34cc36948847399319b35bb2309153 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 4 May 2016 11:12:26 -0400 Subject: [PATCH] handle name resolution errors more gracefully from shell.py This change will catch socket.gaierror exceptions from shell.py and return a more friendly message to the user --- lib/ansible/module_utils/shell.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/shell.py b/lib/ansible/module_utils/shell.py index a01b41b0c5b..3ee770823ed 100644 --- a/lib/ansible/module_utils/shell.py +++ b/lib/ansible/module_utils/shell.py @@ -101,12 +101,15 @@ class Shell(object): if not look_for_keys: look_for_keys = password is None - self.ssh.connect(host, port=port, username=username, password=password, - timeout=timeout, look_for_keys=look_for_keys, pkey=pkey, - key_filename=key_filename, allow_agent=allow_agent) + try: + self.ssh.connect(host, port=port, username=username, password=password, + timeout=timeout, look_for_keys=look_for_keys, pkey=pkey, + key_filename=key_filename, allow_agent=allow_agent) - self.shell = self.ssh.invoke_shell() - self.shell.settimeout(timeout) + self.shell = self.ssh.invoke_shell() + self.shell.settimeout(timeout) + except socket.gaierror: + raise ShellError("unable to resolve host name") if self.kickstart: self.shell.sendall("\n")