diff options
author | James Cammarata <jimi@sngx.net> | 2014-11-19 15:54:47 -0600 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-06-01 14:51:57 -0700 |
commit | 6a63f2a6ba1a3ddd22fcb4d057259740c8df1f6d (patch) | |
tree | 7e9cb307364b99949334bf3d99e8edd6ae029e77 /commands/command.py | |
parent | f8d8af17cdc72500af8319c96004b86ac702a0a4 (diff) | |
download | ansible-modules-core-6a63f2a6ba1a3ddd22fcb4d057259740c8df1f6d.tar.gz |
Command module changes for v2 compatibility
Diffstat (limited to 'commands/command.py')
-rw-r--r-- | commands/command.py | 60 |
1 files changed, 13 insertions, 47 deletions
diff --git a/commands/command.py b/commands/command.py index 131fc4c7..50d32919 100644 --- a/commands/command.py +++ b/commands/command.py @@ -154,12 +154,22 @@ def main(): # the command module is the one ansible module that does not take key=value args # hence don't copy this one if you are looking to build others! - module = CommandModule(argument_spec=dict()) + module = AnsibleModule( + argument_spec=dict( + _raw_params = dict(), + _uses_shell = dict(type='bool', default=False), + chdir = dict(), + executable = dict(), + creates = dict(), + removes = dict(), + warn = dict(type='bool', default=True), + ) + ) - shell = module.params['shell'] + shell = module.params['_uses_shell'] chdir = module.params['chdir'] executable = module.params['executable'] - args = module.params['args'] + args = module.params['_raw_params'] creates = module.params['creates'] removes = module.params['removes'] warn = module.params['warn'] @@ -232,48 +242,4 @@ def main(): from ansible.module_utils.basic import * from ansible.module_utils.splitter import * -# only the command module should ever need to do this -# everything else should be simple key=value - -class CommandModule(AnsibleModule): - - def _handle_aliases(self): - return {} - - def _check_invalid_arguments(self): - pass - - def _load_params(self): - ''' read the input and return a dictionary and the arguments string ''' - args = MODULE_ARGS - params = copy.copy(OPTIONS) - params['shell'] = False - if "#USE_SHELL" in args: - args = args.replace("#USE_SHELL", "") - params['shell'] = True - - items = split_args(args) - - for x in items: - quoted = x.startswith('"') and x.endswith('"') or x.startswith("'") and x.endswith("'") - if '=' in x and not quoted: - # check to see if this is a special parameter for the command - k, v = x.split('=', 1) - v = unquote(v.strip()) - if k in OPTIONS.keys(): - if k == "chdir": - v = os.path.abspath(os.path.expanduser(v)) - if not (os.path.exists(v) and os.path.isdir(v)): - self.fail_json(rc=258, msg="cannot change to directory '%s': path does not exist" % v) - elif k == "executable": - v = os.path.abspath(os.path.expanduser(v)) - if not (os.path.exists(v)): - self.fail_json(rc=258, msg="cannot use executable '%s': file does not exist" % v) - params[k] = v - # Remove any of the above k=v params from the args string - args = PARAM_REGEX.sub('', args) - params['args'] = args.strip() - - return (params, params['args']) - main() |