mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Introduce the 'always_run' task clause.
The 'always_run' task clause allows one to execute a task even in check mode. While here implement Runner.noop_on_check() to check if a runner really should execute its task, with respect to check mode option and 'always_run' clause. Also add the optional 'jinja2' argument to check_conditional() : it allows to give this function a jinja2 expression without exposing the 'jinja2_compare' implementation mechanism.
This commit is contained in:
@@ -36,7 +36,7 @@ class ActionModule(object):
|
||||
|
||||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for this module'))
|
||||
|
||||
args = {}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ActionModule(object):
|
||||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
''' transfer the given module name, plus the async module, then run it '''
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for this module'))
|
||||
|
||||
# shell and command module are the same
|
||||
|
||||
@@ -126,7 +126,7 @@ class ActionModule(object):
|
||||
else:
|
||||
diff = {}
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
if content is not None:
|
||||
os.remove(tmp_content)
|
||||
return ReturnData(conn=conn, result=dict(changed=True), diff=diff)
|
||||
@@ -172,7 +172,7 @@ class ActionModule(object):
|
||||
# don't send down raw=no
|
||||
module_args.pop('raw')
|
||||
module_args = "%s src=%s" % (module_args, pipes.quote(tmp_src))
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
module_args = "%s CHECKMODE=True" % module_args
|
||||
return self.runner._execute_module(conn, tmp, 'file', module_args, inject=inject, complex_args=complex_args)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class ActionModule(object):
|
||||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
''' handler for fetch operations '''
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not (yet) supported for this module'))
|
||||
|
||||
# load up options
|
||||
|
||||
@@ -38,7 +38,7 @@ class ActionModule(object):
|
||||
|
||||
module_args = self.runner._complex_args_hack(complex_args, module_args)
|
||||
|
||||
if self.runner.check:
|
||||
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
|
||||
|
||||
@@ -30,7 +30,7 @@ class ActionModule(object):
|
||||
|
||||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
# in --check mode, always skip this module execution
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True))
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class ActionModule(object):
|
||||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
''' handler for file transfer operations '''
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
# in check mode, always skip this module
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for this module'))
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class ActionModule(object):
|
||||
# run the copy module
|
||||
module_args = "%s src=%s dest=%s original_basename=%s" % (module_args, pipes.quote(xfered), pipes.quote(dest), pipes.quote(os.path.basename(source)))
|
||||
|
||||
if self.runner.check:
|
||||
if self.runner.noop_on_check(inject):
|
||||
return ReturnData(conn=conn, comm_ok=True, result=dict(changed=True), diff=dict(before_header=dest, after_header=source, before=dest_contents, after=resultant))
|
||||
else:
|
||||
res = self.runner._execute_module(conn, tmp, 'copy', module_args, inject=inject, complex_args=complex_args)
|
||||
|
||||
Reference in New Issue
Block a user