Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

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

# (c) 2017 Ansible Project 

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 

 

# Make coding more python3-ish 

from __future__ import (absolute_import, division, print_function) 

__metaclass__ = type 

 

DOCUMENTATION = ''' 

callback: osx_say 

type: notification 

requirements: 

- whitelising in configuration 

- the '/usr/bin/say' command line program (standard on OS X) 

short_description: oneline Ansible screen output 

version_added: historical 

description: 

- This plugin will use the 'say' program to "speak" about play events. 

''' 

 

import subprocess 

import os 

 

from ansible.plugins.callback import CallbackBase 

 

FAILED_VOICE = "Zarvox" 

REGULAR_VOICE = "Trinoids" 

HAPPY_VOICE = "Cellos" 

LASER_VOICE = "Princess" 

SAY_CMD = "/usr/bin/say" 

 

 

class CallbackModule(CallbackBase): 

""" 

makes Ansible much more exciting on OS X. 

""" 

CALLBACK_VERSION = 2.0 

CALLBACK_TYPE = 'notification' 

CALLBACK_NAME = 'osx_say' 

CALLBACK_NEEDS_WHITELIST = True 

 

def __init__(self): 

 

super(CallbackModule, self).__init__() 

 

# 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 

self._display.warning("%s does not exist, plugin %s disabled" % (SAY_CMD, os.path.basename(__file__))) 

 

def say(self, msg, voice): 

subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)]) 

 

def runner_on_failed(self, host, res, ignore_errors=False): 

self.say("Failure on host %s" % host, FAILED_VOICE) 

 

def runner_on_ok(self, host, res): 

self.say("pew", LASER_VOICE) 

 

def runner_on_skipped(self, host, item=None): 

self.say("pew", LASER_VOICE) 

 

def runner_on_unreachable(self, host, res): 

self.say("Failure on host %s" % host, FAILED_VOICE) 

 

def runner_on_async_ok(self, host, res, jid): 

self.say("pew", LASER_VOICE) 

 

def runner_on_async_failed(self, host, res, jid): 

self.say("Failure on host %s" % host, FAILED_VOICE) 

 

def playbook_on_start(self): 

self.say("Running Playbook", REGULAR_VOICE) 

 

def playbook_on_notify(self, host, handler): 

self.say("pew", LASER_VOICE) 

 

def playbook_on_task_start(self, name, is_conditional): 

if not is_conditional: 

self.say("Starting task: %s" % name, REGULAR_VOICE) 

else: 

self.say("Notifying task: %s" % name, REGULAR_VOICE) 

 

def playbook_on_setup(self): 

self.say("Gathering facts", REGULAR_VOICE) 

 

def playbook_on_play_start(self, name): 

self.say("Starting play: %s" % name, HAPPY_VOICE) 

 

def playbook_on_stats(self, stats): 

self.say("Play complete", HAPPY_VOICE)