summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael DeHaan <michael@ansible.com>2014-08-04 10:50:14 -0400
committerMichael DeHaan <michael@ansible.com>2014-08-04 10:50:14 -0400
commit642b183fb6b0632167130774c2ebfc44d88ac278 (patch)
treeb7a39366aecb8324e4dc16b46b18efa14f33c070
parenta7d2e729f81a662430761f95dc250b46acfbc83c (diff)
downloadansible-642b183fb6b0632167130774c2ebfc44d88ac278.tar.gz
Use atomic move function on known host file in paramiko to prevent rare occurance of Control-C
during file operations.
-rw-r--r--lib/ansible/runner/connection_plugins/paramiko_ssh.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/ansible/runner/connection_plugins/paramiko_ssh.py b/lib/ansible/runner/connection_plugins/paramiko_ssh.py
index e71d0824b6..810dff5c4e 100644
--- a/lib/ansible/runner/connection_plugins/paramiko_ssh.py
+++ b/lib/ansible/runner/connection_plugins/paramiko_ssh.py
@@ -381,7 +381,13 @@ class Connection(object):
self.ssh.load_system_host_keys()
self.ssh._host_keys.update(self.ssh._system_host_keys)
- self._save_ssh_host_keys(self.keyfile)
+
+ # save the new keys to a temporary file and move it into place
+ # rather than rewriting the file
+ tmp_keyfile = tempfile.NamedTemporaryFile()
+ self._save_ssh_host_keys(tmp_keyfile)
+ atomic_move(tmp_keyfile.name, self.keyfile)
+ tmp_keyfile.close()
except: