summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael DeHaan <michael.dehaan@gmail.com>2014-03-12 10:55:54 -0400
committerroot <root@llamacube.(none)>2014-03-12 10:56:38 -0400
commita9762357f967f0ef86f36ec7b731d4f0230d7baa (patch)
treed176aa62264d299747de801e1b6c1038c3423d81
parent8588ac5f60ee52f6488802023d3aef53afe2cd33 (diff)
downloadansible-release1.5.2.tar.gz
module.run_command is intended to bypass the shell here, so can't do ">>"release1.5.2
-rw-r--r--lib/ansible/module_utils/basic.py6
-rw-r--r--lib/ansible/module_utils/known_hosts.py4
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
index 67ceb3b605..d2e08f713d 100644
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -1061,6 +1061,12 @@ class AnsibleModule(object):
self.fail_json(cmd=args, rc=rc, stdout=out, stderr=err, msg=msg)
return (rc, out, err)
+ def append_to_file(self, filename, str):
+ filename = os.path.expandvars(os.path.expanduser(filename))
+ fh = open(filename, 'a')
+ fh.write(str)
+ fh.close()
+
def pretty_bytes(self,size):
ranges = (
(1<<70L, 'ZB'),
diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py
index 36f5b87fff..8dc1f3267b 100644
--- a/lib/ansible/module_utils/known_hosts.py
+++ b/lib/ansible/module_utils/known_hosts.py
@@ -91,8 +91,10 @@ def add_host_key(module, fqdn, key_type="rsa"):
if not os.path.exists(os.path.expanduser("~/.ssh/")):
module.fail_json(msg="%s does not exist" % os.path.expanduser("~/.ssh/"))
- this_cmd = "%s -t %s %s >> ~/.ssh/known_hosts" % (keyscan_cmd, key_type, fqdn)
+ this_cmd = "%s -t %s %s" % (keyscan_cmd, key_type, fqdn)
+
rc, out, err = module.run_command(this_cmd)
+ module.append_to_file("~/.ssh/known_hosts", out)
return rc, out, err