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

@@ -474,6 +474,37 @@ class TestPlaybook(unittest.TestCase):
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def test_playbook_always_run(self):
test_callbacks = TestCallbacks()
playbook = ansible.playbook.PlayBook(
playbook=os.path.join(self.test_dir, 'playbook-always-run.yml'),
host_list='test/ansible_hosts',
stats=ans_callbacks.AggregateStats(),
callbacks=test_callbacks,
runner_callbacks=test_callbacks,
check=True
)
actual = playbook.run()
# if different, this will output to screen
print "**ACTUAL**"
print utils.jsonify(actual, format=True)
expected = {
"localhost": {
"changed": 4,
"failures": 0,
"ok": 4,
"skipped": 8,
"unreachable": 0
}
}
print "**EXPECTED**"
print utils.jsonify(expected, format=True)
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def _compare_file_output(self, filename, expected_lines):
actual_lines = []
with open(filename) as f:

View File

@@ -0,0 +1,48 @@
---
- hosts: all
connection: local
gather_facts: False
vars:
var_true: True
var_false: False
var_empty_str: "''"
var_null: ~
tasks:
- action: command echo ping
always_run: yes
- action: command echo pong 1
- action: command echo pong 2
always_run: no
- action: command echo pong 3
always_run: 1 + 1
- action: command echo pong 4
always_run: "''"
- action: command echo pong 5
always_run: False
- action: command echo pong 6
always_run: True
- action: command echo pong 7
always_run: var_true
- action: command echo pong 8
always_run: var_false
- action: command echo pong 9
always_run: var_empty_str
- action: command echo pong 10
always_run: var_null
# this will never run...
- action: command echo pong 11
always_run: yes
when: no