mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Merge branch 'failed_when' of https://github.com/hnakamur/ansible into hnakamur-failed_when
This commit is contained in:
@@ -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()
|
||||
|
||||
15
test/playbook-failed_when.yml
Normal file
15
test/playbook-failed_when.yml
Normal 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]
|
||||
Reference in New Issue
Block a user