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:
Stoned Elipot
2013-08-20 23:09:44 +02:00
parent 7ac3bbc198
commit f0743fc32a
14 changed files with 136 additions and 13 deletions

View File

@@ -37,6 +37,7 @@ import ansible.constants as C
import ansible.inventory
from ansible import utils
from ansible.utils import template
from ansible.utils import check_conditional
from ansible import errors
from ansible import module_common
import poller
@@ -156,6 +157,7 @@ class Runner(object):
self.inventory = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list))
self.module_vars = utils.default(module_vars, lambda: {})
self.always_run = None
self.connector = connection.Connection(self)
self.conditional = conditional
self.module_name = module_name
@@ -935,3 +937,16 @@ class Runner(object):
self.background = time_limit
results = self.run()
return results, poller.AsyncPoller(results, self)
# *****************************************************
def noop_on_check(self, inject):
''' Should the runner run in check mode or not ? '''
# initialize self.always_run on first call
if self.always_run is None:
self.always_run = self.module_vars.get('always_run', False)
self.always_run = check_conditional(
self.always_run, self.basedir, inject, fail_on_undefined=True, jinja2=True)
return (self.check and not self.always_run)