Commit 6ab615c7 by Michael DeHaan

Code cleanup for playbooks, also added 'on_skipped' callback

parent 24964b96
...@@ -60,6 +60,9 @@ class PlaybookCallbacks(object): ...@@ -60,6 +60,9 @@ class PlaybookCallbacks(object):
else: else:
print "ok: [%s] => %s\n" % (host, invocation) 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): def on_import_for_host(self, host, imported_file):
print "%s: importing %s" % (host, imported_file) print "%s: importing %s" % (host, imported_file)
......
...@@ -32,6 +32,9 @@ class TestCallbacks(object): ...@@ -32,6 +32,9 @@ class TestCallbacks(object):
def on_setup_secondary(self): def on_setup_secondary(self):
self.events.append([ 'secondary_setup' ]) self.events.append([ 'secondary_setup' ])
def on_skipped(self, host):
self.events.append([ 'skipped', [ host ]])
def on_import_for_host(self, host, filename): def on_import_for_host(self, host, filename):
self.events.append([ 'import', [ host, filename ]]) self.events.append([ 'import', [ host, filename ]])
...@@ -47,8 +50,9 @@ class TestCallbacks(object): ...@@ -47,8 +50,9 @@ class TestCallbacks(object):
def on_failed(self, host, results): def on_failed(self, host, results):
self.events.append([ 'failed', [ 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 # 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' ]: for k in [ 'ansible_job_id', 'invocation', 'md5sum', 'delta', 'start', 'end' ]:
if k in host_result: if k in host_result:
del host_result[k] del host_result[k]
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"import", "import",
[ [
"127.0.0.1", "127.0.0.1",
"/home/mdehaan/ansible/test/default_os.yml" "/home/mdehaan/ansible/test/CentOS.yml"
] ]
], ],
[ [
...@@ -213,6 +213,28 @@ ...@@ -213,6 +213,28 @@
[ [
"task start", "task start",
[ [
"this should be skipped",
false
]
],
[
"skipped",
[
"127.0.0.1"
]
],
[
"ok",
[
"127.0.0.1",
{
"skipped": true
}
]
],
[
"task start",
[
"on change 1", "on change 1",
true true
] ]
...@@ -222,12 +244,10 @@ ...@@ -222,12 +244,10 @@
[ [
"127.0.0.1", "127.0.0.1",
{ {
"cmd": [ "cmd": "echo this should fire once ",
"/bin/true"
],
"rc": 0, "rc": 0,
"stderr": "", "stderr": "",
"stdout": "" "stdout": "this should fire once"
} }
] ]
], ],
...@@ -243,12 +263,10 @@ ...@@ -243,12 +263,10 @@
[ [
"127.0.0.1", "127.0.0.1",
{ {
"cmd": [ "cmd": "echo this should fire once also ",
"/bin/true"
],
"rc": 0, "rc": 0,
"stderr": "", "stderr": "",
"stdout": "" "stdout": "this should fire once also"
} }
] ]
] ]
...@@ -258,8 +276,9 @@ ...@@ -258,8 +276,9 @@
"changed": 2, "changed": 2,
"dark": 0, "dark": 0,
"failed": 0, "failed": 0,
"resources": 9, "resources": 12,
"skipped": 0 "skipped": 1
} }
} }
} }
# extremely simple test of the most basic of playbook engine/functions # extremely simple test of the most basic of playbook engine/functions
--- ---
- hosts: all - hosts: all
# the 'weasels' string should show up in the output
vars: vars:
answer: "Wuh, I think so, Brain, but if we didn't have ears, we'd look like weasels." answer: "Wuh, I think so, Brain, but if we didn't have ears, we'd look like weasels."
port: 5150 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: vars_files:
- common_vars.yml - common_vars.yml
- [ '$facter_operatingsystem.yml', 'default_os.yml' ] - [ '$facter_operatingsystem.yml', 'default_os.yml' ]
...@@ -46,20 +53,26 @@ ...@@ -46,20 +53,26 @@
async: 10 async: 10
poll: 3 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: handlers:
# in the above test example, this should fire ONCE (at the end) # in the above test example, this should fire ONCE (at the end)
- name: on change 1 - 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) # in the above test example, this should fire ONCE (at the end)
- name: on change 2 - 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 # in the above test example, this should NOT FIRE
- name: on change 3 - 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