mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
add a way for callback to disable itself
The idea is that some plugin would not be called in some specific case, and the callback should decide by itself. Having a way to globally disable it is much cleaner than disabling every method one by one on the plugin side. My use case is for fedora-infrastructure that cannot be run from git checkout since it try to connect to the message bus, but another case would be to bootstrap infrastructure, or to run the code on a test servers without having all the callback infrastructure setup.
This commit is contained in:
parent
10a0f03cdc
commit
12bf9a8b69
3 changed files with 20 additions and 2 deletions
|
@ -17,19 +17,28 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
FAILED_VOICE="Zarvox"
|
||||
REGULAR_VOICE="Trinoids"
|
||||
HAPPY_VOICE="Cellos"
|
||||
LASER_VOICE="Princess"
|
||||
SAY_CMD="/usr/bin/say"
|
||||
|
||||
def say(msg, voice):
|
||||
subprocess.call(["/usr/bin/say", msg, "--voice=%s" % (voice)])
|
||||
subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)])
|
||||
|
||||
class CallbackModule(object):
|
||||
"""
|
||||
makes Ansible much more exciting on OS X.
|
||||
"""
|
||||
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__))
|
||||
|
||||
def on_any(self, *args, **kwargs):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue