Commit b6a34518 by James Cammarata

Fixing checkmode support and some other things in v2

parent daa2c3a9
...@@ -24,6 +24,7 @@ import random ...@@ -24,6 +24,7 @@ import random
from ansible import constants as C from ansible import constants as C
from ansible.template import Templar from ansible.template import Templar
from ansible.utils.boolean import boolean
__all__ = ['ConnectionInformation'] __all__ = ['ConnectionInformation']
...@@ -55,6 +56,9 @@ class ConnectionInformation: ...@@ -55,6 +56,9 @@ class ConnectionInformation:
self.only_tags = set() self.only_tags = set()
self.skip_tags = set() self.skip_tags = set()
self.no_log = False
self.check_mode = False
if play: if play:
self.set_play(play) self.set_play(play)
...@@ -97,6 +101,9 @@ class ConnectionInformation: ...@@ -97,6 +101,9 @@ class ConnectionInformation:
if options.connection: if options.connection:
self.connection = options.connection self.connection = options.connection
if options.check:
self.check_mode = boolean(options.check)
# get the tag info from options, converting a comma-separated list # get the tag info from options, converting a comma-separated list
# of values into a proper list if need be. We check to see if the # of values into a proper list if need be. We check to see if the
# options have the attribute, as it is not always added via the CLI # options have the attribute, as it is not always added via the CLI
...@@ -121,25 +128,36 @@ class ConnectionInformation: ...@@ -121,25 +128,36 @@ class ConnectionInformation:
when merging in data from task overrides. when merging in data from task overrides.
''' '''
self.connection = ci.connection #self.connection = ci.connection
self.remote_user = ci.remote_user #self.remote_user = ci.remote_user
self.password = ci.password #self.password = ci.password
self.port = ci.port #self.port = ci.port
self.su = ci.su #self.su = ci.su
self.su_user = ci.su_user #self.su_user = ci.su_user
self.su_pass = ci.su_pass #self.su_pass = ci.su_pass
self.sudo = ci.sudo #self.sudo = ci.sudo
self.sudo_user = ci.sudo_user #self.sudo_user = ci.sudo_user
self.sudo_pass = ci.sudo_pass #self.sudo_pass = ci.sudo_pass
self.verbosity = ci.verbosity #self.verbosity = ci.verbosity
# other # other
self.no_log = ci.no_log #self.no_log = ci.no_log
self.environment = ci.environment #self.environment = ci.environment
# requested tags # requested tags
self.only_tags = ci.only_tags.copy() #self.only_tags = ci.only_tags.copy()
self.skip_tags = ci.skip_tags.copy() #self.skip_tags = ci.skip_tags.copy()
for field in self._get_fields():
value = getattr(ci, field, None)
if isinstance(value, dict):
setattr(self, field, value.copy())
elif isinstance(value, set):
setattr(self, field, value.copy())
elif isinstance(value, list):
setattr(self, field, value[:])
else:
setattr(self, field, value)
def set_task_override(self, task): def set_task_override(self, task):
''' '''
...@@ -180,6 +198,7 @@ class ConnectionInformation: ...@@ -180,6 +198,7 @@ class ConnectionInformation:
pipes.quote('echo %s; %s' % (success_key, cmd)) pipes.quote('echo %s; %s' % (success_key, cmd))
) )
# FIXME: old code, can probably be removed as it's been commented out for a while
#return ('/bin/sh -c ' + pipes.quote(sudocmd), prompt, success_key) #return ('/bin/sh -c ' + pipes.quote(sudocmd), prompt, success_key)
return (sudocmd, prompt, success_key) return (sudocmd, prompt, success_key)
......
...@@ -301,7 +301,7 @@ class AnsibleModule(object): ...@@ -301,7 +301,7 @@ class AnsibleModule(object):
self.params = self._load_params() self.params = self._load_params()
self._legal_inputs = ['CHECKMODE', 'NO_LOG'] self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log']
self.aliases = self._handle_aliases() self.aliases = self._handle_aliases()
...@@ -817,7 +817,7 @@ class AnsibleModule(object): ...@@ -817,7 +817,7 @@ class AnsibleModule(object):
def _check_for_check_mode(self): def _check_for_check_mode(self):
for (k,v) in self.params.iteritems(): for (k,v) in self.params.iteritems():
if k == 'CHECKMODE': if k == '_ansible_check_mode':
if not self.supports_check_mode: if not self.supports_check_mode:
self.exit_json(skipped=True, msg="remote module does not support check mode") self.exit_json(skipped=True, msg="remote module does not support check mode")
if self.supports_check_mode: if self.supports_check_mode:
...@@ -825,13 +825,13 @@ class AnsibleModule(object): ...@@ -825,13 +825,13 @@ class AnsibleModule(object):
def _check_for_no_log(self): def _check_for_no_log(self):
for (k,v) in self.params.iteritems(): for (k,v) in self.params.iteritems():
if k == 'NO_LOG': if k == '_ansible_no_log':
self.no_log = self.boolean(v) self.no_log = self.boolean(v)
def _check_invalid_arguments(self): def _check_invalid_arguments(self):
for (k,v) in self.params.iteritems(): for (k,v) in self.params.iteritems():
# these should be in legal inputs already # these should be in legal inputs already
#if k in ('CHECKMODE', 'NO_LOG'): #if k in ('_ansible_check_mode', '_ansible_no_log'):
# continue # continue
if k not in self._legal_inputs: if k not in self._legal_inputs:
self.fail_json(msg="unsupported parameter for module: %s" % k) self.fail_json(msg="unsupported parameter for module: %s" % k)
......
Subproject commit e2083bbe8a6baf63a363617f5b4590a3a8ff6e89 Subproject commit 890dfecb565b7287af7a21c1ad93d0051801dce7
...@@ -52,6 +52,8 @@ class ActionBase: ...@@ -52,6 +52,8 @@ class ActionBase:
self._module_loader = module_loader self._module_loader = module_loader
self._shell = self.get_shell() self._shell = self.get_shell()
self._supports_check_mode = True
def get_shell(self): def get_shell(self):
# FIXME: no more inject, get this from the host variables? # FIXME: no more inject, get this from the host variables?
...@@ -327,6 +329,16 @@ class ActionBase: ...@@ -327,6 +329,16 @@ class ActionBase:
if module_args is None: if module_args is None:
module_args = self._task.args module_args = self._task.args
# set check mode in the module arguments, if required
if self._connection_info.check_mode and not self._task.always_run:
if not self._supports_check_mode:
raise AnsibleError("check mode is not supported for this operation")
module_args['_ansible_check_mode'] = True
# set no log in the module arguments, if required
if self._connection_info.no_log:
module_args['_ansible_no_log'] = True
debug("in _execute_module (%s, %s)" % (module_name, module_args)) debug("in _execute_module (%s, %s)" % (module_name, module_args))
(module_style, shebang, module_data) = self._configure_module(module_name=module_name, module_args=module_args) (module_style, shebang, module_data) = self._configure_module(module_name=module_name, module_args=module_args)
...@@ -339,7 +351,7 @@ class ActionBase: ...@@ -339,7 +351,7 @@ class ActionBase:
tmp = self._make_tmp_path() tmp = self._make_tmp_path()
remote_module_path = self._shell.join_path(tmp, module_name) remote_module_path = self._shell.join_path(tmp, module_name)
# FIXME: async stuff here # FIXME: async stuff here?
#if (module_style != 'new' or async_jid is not None or not self._connection._has_pipelining or not C.ANSIBLE_SSH_PIPELINING or C.DEFAULT_KEEP_REMOTE_FILES): #if (module_style != 'new' or async_jid is not None or not self._connection._has_pipelining or not C.ANSIBLE_SSH_PIPELINING or C.DEFAULT_KEEP_REMOTE_FILES):
if remote_module_path: if remote_module_path:
self._transfer_data(remote_module_path, module_data) self._transfer_data(remote_module_path, module_data)
......
...@@ -21,19 +21,6 @@ class ActionModule(ActionBase): ...@@ -21,19 +21,6 @@ class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=dict()): def run(self, tmp=None, task_vars=dict()):
# FIXME: a lot of this should pretty much go away with module
# args being stored within the task being run itself
#if self.runner.noop_on_check(inject):
# if module_name in [ 'shell', 'command' ]:
# return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for %s' % module_name))
# # else let the module parsing code decide, though this will only be allowed for AnsibleModuleCommon using
# # python modules for now
# module_args += " CHECKMODE=True"
#if self.runner.no_log:
# module_args += " NO_LOG=True"
#vv("REMOTE_MODULE %s %s" % (module_name, module_args), host=conn.host) #vv("REMOTE_MODULE %s %s" % (module_name, module_args), host=conn.host)
return self._execute_module(tmp) return self._execute_module(tmp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment