SHOW:
|
|
- or go back to the newest paste.
1 | ''' | |
2 | A wrapper around ansible modules that mangles the arguments | |
3 | ''' | |
4 | import os | |
5 | ||
6 | from ansible import utils | |
7 | from ansible.callbacks import vv | |
8 | ||
9 | def _find_module(name, suffix='.yml'): | |
10 | '''find a module with a different suffix''' | |
11 | dirs = utils.plugins.module_finder.print_paths().split(os.pathsep) | |
12 | for d in dirs: | |
13 | path = os.path.join(d, "%s%s" % (name, suffix)) | |
14 | if os.path.exists(path): | |
15 | return path | |
16 | ||
17 | class ActionModule(object): | |
18 | ||
19 | def __init__(self, runner): | |
20 | self.runner = runner | |
21 | ||
22 | def run(self, conn, tmp, module_name, module_args, inject): | |
23 | '''use a module wrapper''' | |
24 | ||
25 | path = _find_module(module_name) | |
26 | if path: | |
27 | vv('using module wrapper: %s' % path, host=conn.host) | |
28 | ||
29 | # we may want to use args in the wrapper | |
30 | args = utils.parse_kv(module_args) | |
31 | inject.update(args) | |
32 | ||
33 | data = utils.parse_yaml_from_file(path) | |
34 | data = utils.template_ds(self.runner.basedir, data, inject) | |
35 | ||
36 | # apply defaults | |
37 | if 'defaults' in data: | |
38 | args = dict(data['defaults'].items() + args.items()) | |
39 | module_args = " ".join("%s='%s'" % i for i in args.items()) | |
40 | - | module_args = " ".join("%s='%s'" % i for i in args.items()) |
40 | + | |
41 | # possibly change the name | |
42 | module_name = data.get('module', module_name) | |
43 | ||
44 | ### upstream normal plugin follows ### | |
45 | ||
46 | # shell and command are the same module | |
47 | if module_name == 'shell': | |
48 | module_name = 'command' | |
49 | module_args += " #USE_SHELL" | |
50 | ||
51 | vv("REMOTE_MODULE %s %s" % (module_name, module_args), host=conn.host) | |
52 | return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject) |