This reverts commit bd49a835b49050d18b2982e4d0b98dddddee0a5e.
James Cammarata authored on 2014/08/07 05:32:31... | ... |
@@ -29,7 +29,6 @@ import pipes |
29 | 29 |
import socket |
30 | 30 |
import random |
31 | 31 |
import logging |
32 |
-import tempfile |
|
33 | 32 |
import traceback |
34 | 33 |
import fcntl |
35 | 34 |
import re |
... | ... |
@@ -40,6 +39,7 @@ from ansible.callbacks import vvv |
40 | 40 |
from ansible import errors |
41 | 41 |
from ansible import utils |
42 | 42 |
from ansible import constants as C |
43 |
+from ansible.module_utils.basic import atomic_move |
|
43 | 44 |
|
44 | 45 |
AUTHENTICITY_MSG=""" |
45 | 46 |
paramiko: The authenticity of host '%s' can't be established. |
... | ... |
@@ -381,25 +381,7 @@ class Connection(object): |
381 | 381 |
|
382 | 382 |
self.ssh.load_system_host_keys() |
383 | 383 |
self.ssh._host_keys.update(self.ssh._system_host_keys) |
384 |
- |
|
385 |
- # gather information about the current key file, so |
|
386 |
- # we can ensure the new file has the correct mode/owner |
|
387 |
- |
|
388 |
- key_dir = os.path.dirname(self.keyfile) |
|
389 |
- key_stat = os.stat(self.keyfile) |
|
390 |
- |
|
391 |
- # Save the new keys to a temporary file and move it into place |
|
392 |
- # rather than rewriting the file. We set delete=False because |
|
393 |
- # the file will be moved into place rather than cleaned up. |
|
394 |
- |
|
395 |
- tmp_keyfile = tempfile.NamedTemporaryFile(dir=key_dir, delete=False) |
|
396 |
- os.chmod(tmp_keyfile.name, key_stat.st_mode & 07777) |
|
397 |
- os.chown(tmp_keyfile.name, key_stat.st_uid, key_stat.st_gid) |
|
398 |
- |
|
399 |
- self._save_ssh_host_keys(tmp_keyfile.name) |
|
400 |
- tmp_keyfile.close() |
|
401 |
- |
|
402 |
- os.rename(tmp_keyfile.name, self.keyfile) |
|
384 |
+ self._save_ssh_host_keys(self.keyfile) |
|
403 | 385 |
|
404 | 386 |
except: |
405 | 387 |
|