Commit 6ab615c7 by Michael DeHaan

Code cleanup for playbooks, also added 'on_skipped' callback

parent 24964b96
......@@ -60,6 +60,9 @@ class PlaybookCallbacks(object):
else:
print "ok: [%s] => %s\n" % (host, invocation)
def on_skipped(self, host):
print "skipping: [%s]\n" % host
def on_import_for_host(self, host, imported_file):
print "%s: importing %s" % (host, imported_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]
......
......@@ -31,7 +31,7 @@
"import",
[
"127.0.0.1",
"/home/mdehaan/ansible/test/default_os.yml"
"/home/mdehaan/ansible/test/CentOS.yml"
]
],
[
......@@ -213,6 +213,28 @@
[
"task start",
[
"this should be skipped",
false
]
],
[
"skipped",
[
"127.0.0.1"
]
],
[
"ok",
[
"127.0.0.1",
{
"skipped": true
}
]
],
[
"task start",
[
"on change 1",
true
]
......@@ -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
}
}
}
# 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'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment