1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Heikki Hokkanen 2014-01-28 22:10:13 +02:00 committed by James Cammarata
parent 7f6dcf3949
commit b6875b3b87

View file

@ -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