module.run_command is intended to bypass the shell here, so can't do ">>"

pull/6444/head
Michael DeHaan 11 years ago
parent 7f38cff989
commit cfabc2e28a

@ -1089,6 +1089,12 @@ class AnsibleModule(object):
self.fail_json(cmd=clean_args, rc=rc, stdout=out, stderr=err, msg=msg) self.fail_json(cmd=clean_args, rc=rc, stdout=out, stderr=err, msg=msg)
return (rc, out, err) 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): def pretty_bytes(self,size):
ranges = ( ranges = (
(1<<70L, 'ZB'), (1<<70L, 'ZB'),

@ -91,8 +91,10 @@ def add_host_key(module, fqdn, key_type="rsa"):
if not os.path.exists(os.path.expanduser("~/.ssh/")): if not os.path.exists(os.path.expanduser("~/.ssh/")):
module.fail_json(msg="%s does not exist" % 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) rc, out, err = module.run_command(this_cmd)
module.append_to_file("~/.ssh/known_hosts", out)
return rc, out, err return rc, out, err

Loading…
Cancel
Save