Code cleanup for playbooks, also added 'on_skipped' callback

This commit is contained in:
Michael DeHaan
2012-03-23 20:51:15 -04:00
parent 24964b9660
commit 6ab615c724
5 changed files with 159 additions and 163 deletions

View File

@@ -32,6 +32,9 @@ class TestCallbacks(object):
def on_setup_secondary(self):
self.events.append([ 'secondary_setup' ])
def on_skipped(self, host):
self.events.append([ 'skipped', [ host ]])
def on_import_for_host(self, host, filename):
self.events.append([ 'import', [ host, filename ]])
@@ -47,8 +50,9 @@ class TestCallbacks(object):
def on_failed(self, host, results):
self.events.append([ 'failed', [ host, results ]])
def on_ok(self, host, host_result):
def on_ok(self, host, result):
# delete certain info from host_result to make test comparisons easier
host_result = result.copy()
for k in [ 'ansible_job_id', 'invocation', 'md5sum', 'delta', 'start', 'end' ]:
if k in host_result:
del host_result[k]

View File

@@ -31,7 +31,7 @@
"import",
[
"127.0.0.1",
"/home/mdehaan/ansible/test/default_os.yml"
"/home/mdehaan/ansible/test/CentOS.yml"
]
],
[
@@ -210,6 +210,28 @@
}
]
],
[
"task start",
[
"this should be skipped",
false
]
],
[
"skipped",
[
"127.0.0.1"
]
],
[
"ok",
[
"127.0.0.1",
{
"skipped": true
}
]
],
[
"task start",
[
@@ -222,12 +244,10 @@
[
"127.0.0.1",
{
"cmd": [
"/bin/true"
],
"cmd": "echo this should fire once ",
"rc": 0,
"stderr": "",
"stdout": ""
"stdout": "this should fire once"
}
]
],
@@ -243,12 +263,10 @@
[
"127.0.0.1",
{
"cmd": [
"/bin/true"
],
"cmd": "echo this should fire once also ",
"rc": 0,
"stderr": "",
"stdout": ""
"stdout": "this should fire once also"
}
]
]
@@ -258,8 +276,9 @@
"changed": 2,
"dark": 0,
"failed": 0,
"resources": 9,
"skipped": 0
"resources": 12,
"skipped": 1
}
}
}

View File

@@ -1,9 +1,16 @@
# extremely simple test of the most basic of playbook engine/functions
---
- hosts: all
# the 'weasels' string should show up in the output
vars:
answer: "Wuh, I think so, Brain, but if we didn't have ears, we'd look like weasels."
port: 5150
# we should have import events for common_vars and CentOS.yml (if run on CentOS)
# sorry, tests are a bit platform specific just for now
vars_files:
- common_vars.yml
- [ '$facter_operatingsystem.yml', 'default_os.yml' ]
@@ -46,20 +53,26 @@
async: 10
poll: 3
# the following command should be skipped
- name: this should be skipped
action: shell echo 'if you see this, this is wrong ($facter_operatingsystem)'
only_if: "'$facter_operatingsystem' == 'Imaginary'"
handlers:
# in the above test example, this should fire ONCE (at the end)
- name: on change 1
action: command /bin/true
action: shell echo 'this should fire once'
# in the above test example, this should fire ONCE (at the end)
- name: on change 2
action: command /bin/true
action: shell echo 'this should fire once also'
# in the above test example, this should NOT FIRE
- name: on change 3
action: command /bin/true
action: shell echo 'if you see this, this is wrong'