Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- A wrapper around ansible modules that mangles the arguments
- '''
- import os
- from ansible import utils
- from ansible.callbacks import vv
- def _find_module(name, suffix='.yml'):
- '''find a module with a different suffix'''
- dirs = utils.plugins.module_finder.print_paths().split(os.pathsep)
- for d in dirs:
- path = os.path.join(d, "%s%s" % (name, suffix))
- if os.path.exists(path):
- return path
- class ActionModule(object):
- def __init__(self, runner):
- self.runner = runner
- def run(self, conn, tmp, module_name, module_args, inject):
- '''use a module wrapper'''
- path = _find_module(module_name)
- if path:
- vv('using module wrapper: %s' % path, host=conn.host)
- # we may want to use args in the wrapper
- args = utils.parse_kv(module_args)
- inject.update(args)
- data = utils.parse_yaml_from_file(path)
- data = utils.template_ds(self.runner.basedir, data, inject)
- # apply defaults
- if 'defaults' in data:
- args = dict(data['defaults'].items() + args.items())
- module_args = " ".join("%s='%s'" % i for i in args.items())
- # possibly change the name
- module_name = data.get('module', module_name)
- ### upstream normal plugin follows ###
- # shell and command are the same module
- if module_name == 'shell':
- module_name = 'command'
- module_args += " #USE_SHELL"
- vv("REMOTE_MODULE %s %s" % (module_name, module_args), host=conn.host)
- return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject)
Advertisement
Add Comment
Please, Sign In to add comment