From b6875b3b874aebd4ef3cf576fbbdfa8bcf5ea101 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Tue, 28 Jan 2014 22:10:13 +0200 Subject: [PATCH] Fix .ssh/known_hosts path expansion. In particular, do not rely on the $USER environment variable always existing. tmux for example seems to clear it, causing lots of invalid messages: "previous known host file not found" This broke in commit 80fd22dc, but instead of reverting that commit, we now fall back to expanding just ~ when $USER is not set. --- lib/ansible/runner/connection_plugins/ssh.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py index f91460c2e2..8d82a2617e 100644 --- a/lib/ansible/runner/connection_plugins/ssh.py +++ b/lib/ansible/runner/connection_plugins/ssh.py @@ -117,7 +117,11 @@ class Connection(object): os.close(self.wfd) def not_in_host_file(self, host): - host_file = os.path.expanduser(os.path.expandvars("~${USER}/.ssh/known_hosts")) + if 'USER' in os.environ: + host_file = os.path.expandvars("~${USER}/.ssh/known_hosts") + else: + host_file = "~/.ssh/known_hosts" + host_file = os.path.expanduser(host_file) if not os.path.exists(host_file): print "previous known host file not found" return True