osx_say.py 3.19 KB
Newer Older
Michael DeHaan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

# (C) 2012, Michael DeHaan, <michael.dehaan@gmail.com>

# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

import subprocess
20
import os
Michael DeHaan committed
21 22 23 24

FAILED_VOICE="Zarvox"
REGULAR_VOICE="Trinoids"
HAPPY_VOICE="Cellos"
25
LASER_VOICE="Princess"
26
SAY_CMD="/usr/bin/say"
Michael DeHaan committed
27 28

def say(msg, voice):
29
    subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)])
Michael DeHaan committed
30 31 32

class CallbackModule(object):
    """
Michael DeHaan committed
33
    makes Ansible much more exciting on OS X.
Michael DeHaan committed
34
    """
35 36 37 38 39 40 41
    def __init__(self):
        # plugin disable itself if say is not present
        # ansible will not call any callback if disabled is set to True
        if not os.path.exists(SAY_CMD):
            self.disabled = True
            print "%s does not exist, plugin %s disabled" % \
                    (SAY_CMD, os.path.basename(__file__))
Michael DeHaan committed
42 43 44 45 46 47 48 49

    def on_any(self, *args, **kwargs):
        pass

    def runner_on_failed(self, host, res, ignore_errors=False):
        say("Failure on host %s" % host, FAILED_VOICE)

    def runner_on_ok(self, host, res):
50
        say("pew", LASER_VOICE)
Michael DeHaan committed
51 52 53 54 55

    def runner_on_error(self, host, msg):
        pass

    def runner_on_skipped(self, host, item=None):
56
        say("pew", LASER_VOICE)
Michael DeHaan committed
57 58 59 60 61 62 63 64 65 66 67

    def runner_on_unreachable(self, host, res):
        say("Failure on host %s" % host, FAILED_VOICE)

    def runner_on_no_hosts(self):
        pass

    def runner_on_async_poll(self, host, res, jid, clock):
        pass

    def runner_on_async_ok(self, host, res, jid):
68
        say("pew", LASER_VOICE)
Michael DeHaan committed
69 70 71 72 73 74 75 76

    def runner_on_async_failed(self, host, res, jid):
        say("Failure on host %s" % host, FAILED_VOICE)

    def playbook_on_start(self):
        say("Running Playbook", REGULAR_VOICE)

    def playbook_on_notify(self, host, handler):
77
        say("pew", LASER_VOICE)
Michael DeHaan committed
78

79 80 81 82 83 84
    def playbook_on_no_hosts_matched(self):
        pass

    def playbook_on_no_hosts_remaining(self):
        pass

Michael DeHaan committed
85
    def playbook_on_task_start(self, name, is_conditional):
86 87 88 89
        if not is_conditional:
            say("Starting task: %s" % name, REGULAR_VOICE)
        else:
            say("Notifying task: %s" % name, REGULAR_VOICE)
Michael DeHaan committed
90

91
    def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
Michael DeHaan committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        pass

    def playbook_on_setup(self):
        say("Gathering facts", REGULAR_VOICE)

    def playbook_on_import_for_host(self, host, imported_file):
        pass

    def playbook_on_not_import_for_host(self, host, missing_file):
        pass

    def playbook_on_play_start(self, pattern):
        say("Starting play: %s" % pattern, HAPPY_VOICE)

    def playbook_on_stats(self, stats):
        say("Play complete", HAPPY_VOICE)