Merge branch 'failed_when' of https://github.com/hnakamur/ansible into hnakamur-failed_when

This commit is contained in:
James Cammarata
2013-09-16 07:35:34 -05:00
6 changed files with 61 additions and 8 deletions

View File

@@ -474,6 +474,34 @@ class TestPlaybook(unittest.TestCase):
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def test_playbook_failed_when(self):
test_callbacks = TestCallbacks()
playbook = ansible.playbook.PlayBook(
playbook=os.path.join(self.test_dir, 'playbook-failed_when.yml'),
host_list='test/ansible_hosts',
stats=ans_callbacks.AggregateStats(),
callbacks=test_callbacks,
runner_callbacks=test_callbacks
)
actual = playbook.run()
# if different, this will output to screen
print "**ACTUAL**"
print utils.jsonify(actual, format=True)
expected = {
"localhost": {
"changed": 2,
"failures": 1,
"ok": 2,
"skipped": 0,
"unreachable": 0
}
}
print "**EXPECTED**"
print utils.jsonify(expected, format=True)
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def test_playbook_always_run(self):
test_callbacks = TestCallbacks()

View File

@@ -0,0 +1,15 @@
---
- hosts: all
connection: local
gather_facts: False
tasks:
- action: shell exit 0
register: exit
failed_when: not exit.rc in [0, 1]
- action: shell exit 1
register: exit
failed_when: exit.rc not in [0, 1]
- action: shell exit 2
register: exit
failed_when: exit.rc not in [0, 1]