Tweaking daisychain internals to allow get_url to modify the path destination when downloading to a directory.

Minor module refactoring.
This commit is contained in:
Michael DeHaan 2012-07-22 11:08:16 -04:00
commit 0b891fc8fb
4 changed files with 90 additions and 146 deletions

View file

@ -128,22 +128,27 @@ class AnsibleModule(object):
log_args = re.sub(r'password=.+ (.*)', r"password=NOT_LOGGING_PASSWORD \1", self.args)
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % log_args)
def jsonify(self, data):
return json.dumps(data)
def exit_json(self, **kwargs):
''' return from the module, without error '''
print json.dumps(kwargs)
print self.jsonify(kwargs)
sys.exit(0)
def fail_json(self, **kwargs):
''' return from the module, with an error message '''
assert 'msg' in kwargs, "implementation error -- msg to explain the error is required"
kwargs['failed'] = True
print json.dumps(kwargs)
print self.jsonify(kwargs)
sys.exit(1)
def md5(self, filename):
''' Return MD5 hex digest of local file, or None if file is not present. '''
if not os.path.exists(filename):
return None
if os.path.isdir(filename):
self.fail_json(msg="attempted to take md5sum of directory: %s" % filename)
digest = _md5()
blocksize = 64 * 1024
infile = open(filename, 'rb')

View file

@ -537,6 +537,14 @@ class Runner(object):
group_hosts[g.name] = [ h.name for h in g.hosts ]
inject['groups'] = group_hosts
# allow module args to work as a dictionary
# though it is usually a string
new_args = ""
if type(self.module_args) == dict:
for (k,v) in self.module_args.iteritems():
new_args = new_args + "%s='%s' " % (k,v)
self.module_args = new_args
conditional = utils.template(self.conditional, inject)
if not eval(conditional):
result = utils.jsonify(dict(skipped=True))
@ -568,6 +576,8 @@ class Runner(object):
if result.is_successful() and 'daisychain' in result.result:
chained = True
self.module_name = result.result['daisychain']
if 'daisychain_args' in result.result:
self.module_args = result.result['daisychain_args']
result2 = self._executor_internal_inner(host, inject, port)
changed = result.result.get('changed',False) or result2.result.get('changed',False)
result.result.update(result2.result)