From bc93732b1d6da07dc6c6d69924a7b52c0fd16266 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 24 Mar 2014 16:32:31 -0500 Subject: [PATCH] Catch permissions errors related to opening a known_hosts file in modules Fixes #6644 --- lib/ansible/module_utils/known_hosts.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index dfd684c2328..e6912d91846 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -87,9 +87,16 @@ def not_in_host_file(self, host): if not os.path.exists(hf): hfiles_not_found += 1 continue - host_fh = open(hf) - data = host_fh.read() - host_fh.close() + + try: + host_fh = open(hf) + except IOError, e: + hfiles_not_found += 1 + continue + else: + data = host_fh.read() + host_fh.close() + for line in data.split("\n"): if line is None or line.find(" ") == -1: continue