diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2015-07-08 20:37:17 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2015-07-10 10:30:33 -0400 |
commit | d0c6d2ff1c9f1bcf7c6a1fc717daaeffa5f38b48 (patch) | |
tree | de7c17a53860b1d3d3256f878ed125bfc3090882 | |
parent | 50d54b1be7759eb360cd2bc8dc9484b1f85ff73d (diff) | |
download | ansible-d0c6d2ff1c9f1bcf7c6a1fc717daaeffa5f38b48.tar.gz |
poreted log_plays, syslog_json and osx_say callbacks to v2
renamed plugins to contrib (they are not really plugins)
rewrote README.md to reflect new usage
added new dir to setup.py so it gets copied with installation, in views
of making using inventory scripts easier in teh future
-rw-r--r-- | contrib/README.md | 17 | ||||
-rw-r--r-- | contrib/inventory/abiquo.ini (renamed from plugins/inventory/abiquo.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/abiquo.py (renamed from plugins/inventory/abiquo.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/apache-libcloud.py (renamed from plugins/inventory/apache-libcloud.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/cloudstack.ini (renamed from plugins/inventory/cloudstack.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/cloudstack.py (renamed from plugins/inventory/cloudstack.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/cobbler.ini (renamed from plugins/inventory/cobbler.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/cobbler.py (renamed from plugins/inventory/cobbler.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/collins.ini (renamed from plugins/inventory/collins.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/collins.py (renamed from plugins/inventory/collins.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/consul.ini (renamed from plugins/inventory/consul.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/consul_io.py (renamed from plugins/inventory/consul_io.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/digital_ocean.ini (renamed from plugins/inventory/digital_ocean.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/digital_ocean.py (renamed from plugins/inventory/digital_ocean.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/docker.py (renamed from plugins/inventory/docker.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/docker.yml (renamed from plugins/inventory/docker.yml) | 0 | ||||
-rw-r--r-- | contrib/inventory/ec2.ini (renamed from plugins/inventory/ec2.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/ec2.py (renamed from plugins/inventory/ec2.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/fleet.py (renamed from plugins/inventory/fleet.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/freeipa.py (renamed from plugins/inventory/freeipa.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/gce.ini (renamed from plugins/inventory/gce.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/gce.py (renamed from plugins/inventory/gce.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/jail.py (renamed from plugins/inventory/jail.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/landscape.py (renamed from plugins/inventory/landscape.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/libcloud.ini (renamed from plugins/inventory/libcloud.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/libvirt_lxc.py (renamed from plugins/inventory/libvirt_lxc.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/linode.ini (renamed from plugins/inventory/linode.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/linode.py (renamed from plugins/inventory/linode.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/nova.ini (renamed from plugins/inventory/nova.ini) | 0 | ||||
-rw-r--r-- | contrib/inventory/nova.py (renamed from plugins/inventory/nova.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/openshift.py (renamed from plugins/inventory/openshift.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/openstack.py (renamed from plugins/inventory/openstack.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/openstack.yml (renamed from plugins/inventory/openstack.yml) | 0 | ||||
-rw-r--r-- | contrib/inventory/ovirt.ini (renamed from plugins/inventory/ovirt.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/ovirt.py (renamed from plugins/inventory/ovirt.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/rax.ini (renamed from plugins/inventory/rax.ini) | 0 | ||||
-rw-r--r-- | contrib/inventory/rax.py (renamed from plugins/inventory/rax.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/serf.py (renamed from plugins/inventory/serf.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/softlayer.py (renamed from plugins/inventory/softlayer.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/spacewalk.py (renamed from plugins/inventory/spacewalk.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/ssh_config.py (renamed from plugins/inventory/ssh_config.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/vagrant.py (renamed from plugins/inventory/vagrant.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/vbox.py (renamed from plugins/inventory/vbox.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/vmware.ini (renamed from plugins/inventory/vmware.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/vmware.py (renamed from plugins/inventory/vmware.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/windows_azure.ini (renamed from plugins/inventory/windows_azure.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/windows_azure.py (renamed from plugins/inventory/windows_azure.py) | 0 | ||||
-rw-r--r-- | contrib/inventory/zabbix.ini (renamed from plugins/inventory/zabbix.ini) | 0 | ||||
-rwxr-xr-x | contrib/inventory/zabbix.py (renamed from plugins/inventory/zabbix.py) | 0 | ||||
-rwxr-xr-x | contrib/inventory/zone.py (renamed from plugins/inventory/zone.py) | 0 | ||||
-rw-r--r-- | lib/ansible/plugins/callback/log_plays.py | 85 | ||||
-rw-r--r-- | lib/ansible/plugins/callback/osx_say.py (renamed from plugins/callbacks/osx_say.py) | 70 | ||||
-rw-r--r-- | lib/ansible/plugins/callback/syslog_json.py (renamed from plugins/callbacks/syslog_json.py) | 49 | ||||
-rw-r--r-- | plugins/README.md | 35 | ||||
-rw-r--r-- | plugins/callbacks/log_plays.py | 116 | ||||
-rw-r--r-- | setup.py | 2 |
56 files changed, 138 insertions, 236 deletions
diff --git a/contrib/README.md b/contrib/README.md new file mode 100644 index 0000000000..dab0da4ba7 --- /dev/null +++ b/contrib/README.md @@ -0,0 +1,17 @@ +inventory +========= + +Inventory scripts allow you to store your hosts, groups, and variables in any way +you like. Examples include discovering inventory from EC2 or pulling it from +Cobbler. These could also be used to interface with LDAP or database. + +chmod +x an inventory plugin and either name it /etc/ansible/hosts or use ansible +with -i to designate the path to the script. You might also need to copy a configuration +file with the same name and/or set environment variables, the scripts or configuration +files have more details. + +contributions welcome +===================== + +Send in pull requests to add plugins of your own. The sky is the limit! + diff --git a/plugins/inventory/abiquo.ini b/contrib/inventory/abiquo.ini index 25d015c4de..25d015c4de 100644 --- a/plugins/inventory/abiquo.ini +++ b/contrib/inventory/abiquo.ini diff --git a/plugins/inventory/abiquo.py b/contrib/inventory/abiquo.py index a6030c58b8..a6030c58b8 100755 --- a/plugins/inventory/abiquo.py +++ b/contrib/inventory/abiquo.py diff --git a/plugins/inventory/apache-libcloud.py b/contrib/inventory/apache-libcloud.py index 151daeefe0..151daeefe0 100755 --- a/plugins/inventory/apache-libcloud.py +++ b/contrib/inventory/apache-libcloud.py diff --git a/plugins/inventory/cloudstack.ini b/contrib/inventory/cloudstack.ini index 43777b593f..43777b593f 100644 --- a/plugins/inventory/cloudstack.ini +++ b/contrib/inventory/cloudstack.ini diff --git a/plugins/inventory/cloudstack.py b/contrib/inventory/cloudstack.py index 426cf163fd..426cf163fd 100755 --- a/plugins/inventory/cloudstack.py +++ b/contrib/inventory/cloudstack.py diff --git a/plugins/inventory/cobbler.ini b/contrib/inventory/cobbler.ini index b7b63595de..b7b63595de 100644 --- a/plugins/inventory/cobbler.ini +++ b/contrib/inventory/cobbler.ini diff --git a/plugins/inventory/cobbler.py b/contrib/inventory/cobbler.py index f352c8cf9d..f352c8cf9d 100755 --- a/plugins/inventory/cobbler.py +++ b/contrib/inventory/cobbler.py diff --git a/plugins/inventory/collins.ini b/contrib/inventory/collins.ini index 748fcf854a..748fcf854a 100644 --- a/plugins/inventory/collins.ini +++ b/contrib/inventory/collins.ini diff --git a/plugins/inventory/collins.py b/contrib/inventory/collins.py index 775beecb1d..775beecb1d 100755 --- a/plugins/inventory/collins.py +++ b/contrib/inventory/collins.py diff --git a/plugins/inventory/consul.ini b/contrib/inventory/consul.ini index 8761494ab9..8761494ab9 100644 --- a/plugins/inventory/consul.ini +++ b/contrib/inventory/consul.ini diff --git a/plugins/inventory/consul_io.py b/contrib/inventory/consul_io.py index 4e40f96873..4e40f96873 100755 --- a/plugins/inventory/consul_io.py +++ b/contrib/inventory/consul_io.py diff --git a/plugins/inventory/digital_ocean.ini b/contrib/inventory/digital_ocean.ini index 021899731c..021899731c 100644 --- a/plugins/inventory/digital_ocean.ini +++ b/contrib/inventory/digital_ocean.ini diff --git a/plugins/inventory/digital_ocean.py b/contrib/inventory/digital_ocean.py index 1323a384ba..1323a384ba 100755 --- a/plugins/inventory/digital_ocean.py +++ b/contrib/inventory/digital_ocean.py diff --git a/plugins/inventory/docker.py b/contrib/inventory/docker.py index 0460b2d3bd..0460b2d3bd 100755 --- a/plugins/inventory/docker.py +++ b/contrib/inventory/docker.py diff --git a/plugins/inventory/docker.yml b/contrib/inventory/docker.yml index 53e3c3f364..53e3c3f364 100644 --- a/plugins/inventory/docker.yml +++ b/contrib/inventory/docker.yml diff --git a/plugins/inventory/ec2.ini b/contrib/inventory/ec2.ini index 4cd78305c7..4cd78305c7 100644 --- a/plugins/inventory/ec2.ini +++ b/contrib/inventory/ec2.ini diff --git a/plugins/inventory/ec2.py b/contrib/inventory/ec2.py index 5d8b558aa0..5d8b558aa0 100755 --- a/plugins/inventory/ec2.py +++ b/contrib/inventory/ec2.py diff --git a/plugins/inventory/fleet.py b/contrib/inventory/fleet.py index 3267aeb2ea..3267aeb2ea 100755 --- a/plugins/inventory/fleet.py +++ b/contrib/inventory/fleet.py diff --git a/plugins/inventory/freeipa.py b/contrib/inventory/freeipa.py index 05a8dba356..05a8dba356 100755 --- a/plugins/inventory/freeipa.py +++ b/contrib/inventory/freeipa.py diff --git a/plugins/inventory/gce.ini b/contrib/inventory/gce.ini index fd3325c79f..fd3325c79f 100644 --- a/plugins/inventory/gce.ini +++ b/contrib/inventory/gce.ini diff --git a/plugins/inventory/gce.py b/contrib/inventory/gce.py index 5fe3db93f8..5fe3db93f8 100755 --- a/plugins/inventory/gce.py +++ b/contrib/inventory/gce.py diff --git a/plugins/inventory/jail.py b/contrib/inventory/jail.py index 29c34aef8e..29c34aef8e 100755 --- a/plugins/inventory/jail.py +++ b/contrib/inventory/jail.py diff --git a/plugins/inventory/landscape.py b/contrib/inventory/landscape.py index 4b53171c34..4b53171c34 100755 --- a/plugins/inventory/landscape.py +++ b/contrib/inventory/landscape.py diff --git a/plugins/inventory/libcloud.ini b/contrib/inventory/libcloud.ini index 7592c41cd0..7592c41cd0 100644 --- a/plugins/inventory/libcloud.ini +++ b/contrib/inventory/libcloud.ini diff --git a/plugins/inventory/libvirt_lxc.py b/contrib/inventory/libvirt_lxc.py index ff037265cd..ff037265cd 100755 --- a/plugins/inventory/libvirt_lxc.py +++ b/contrib/inventory/libvirt_lxc.py diff --git a/plugins/inventory/linode.ini b/contrib/inventory/linode.ini index ec7f007fac..ec7f007fac 100644 --- a/plugins/inventory/linode.ini +++ b/contrib/inventory/linode.ini diff --git a/plugins/inventory/linode.py b/contrib/inventory/linode.py index cbce5f8a69..cbce5f8a69 100755 --- a/plugins/inventory/linode.py +++ b/contrib/inventory/linode.py diff --git a/plugins/inventory/nova.ini b/contrib/inventory/nova.ini index c5cfeef810..c5cfeef810 100644 --- a/plugins/inventory/nova.ini +++ b/contrib/inventory/nova.ini diff --git a/plugins/inventory/nova.py b/contrib/inventory/nova.py index af2e7a0760..af2e7a0760 100644 --- a/plugins/inventory/nova.py +++ b/contrib/inventory/nova.py diff --git a/plugins/inventory/openshift.py b/contrib/inventory/openshift.py index c6acb6ff8c..c6acb6ff8c 100755 --- a/plugins/inventory/openshift.py +++ b/contrib/inventory/openshift.py diff --git a/plugins/inventory/openstack.py b/contrib/inventory/openstack.py index 819380c796..819380c796 100755 --- a/plugins/inventory/openstack.py +++ b/contrib/inventory/openstack.py diff --git a/plugins/inventory/openstack.yml b/contrib/inventory/openstack.yml index a99bb02058..a99bb02058 100644 --- a/plugins/inventory/openstack.yml +++ b/contrib/inventory/openstack.yml diff --git a/plugins/inventory/ovirt.ini b/contrib/inventory/ovirt.ini index a52f9d63ff..a52f9d63ff 100644 --- a/plugins/inventory/ovirt.ini +++ b/contrib/inventory/ovirt.ini diff --git a/plugins/inventory/ovirt.py b/contrib/inventory/ovirt.py index 4cb4b09eae..4cb4b09eae 100755 --- a/plugins/inventory/ovirt.py +++ b/contrib/inventory/ovirt.py diff --git a/plugins/inventory/rax.ini b/contrib/inventory/rax.ini index 5a269e16a3..5a269e16a3 100644 --- a/plugins/inventory/rax.ini +++ b/contrib/inventory/rax.ini diff --git a/plugins/inventory/rax.py b/contrib/inventory/rax.py index 10b72d322b..10b72d322b 100644 --- a/plugins/inventory/rax.py +++ b/contrib/inventory/rax.py diff --git a/plugins/inventory/serf.py b/contrib/inventory/serf.py index e1340da92d..e1340da92d 100755 --- a/plugins/inventory/serf.py +++ b/contrib/inventory/serf.py diff --git a/plugins/inventory/softlayer.py b/contrib/inventory/softlayer.py index d2a15b1218..d2a15b1218 100755 --- a/plugins/inventory/softlayer.py +++ b/contrib/inventory/softlayer.py diff --git a/plugins/inventory/spacewalk.py b/contrib/inventory/spacewalk.py index 89e045056c..89e045056c 100755 --- a/plugins/inventory/spacewalk.py +++ b/contrib/inventory/spacewalk.py diff --git a/plugins/inventory/ssh_config.py b/contrib/inventory/ssh_config.py index 7c04c8cc6d..7c04c8cc6d 100755 --- a/plugins/inventory/ssh_config.py +++ b/contrib/inventory/ssh_config.py diff --git a/plugins/inventory/vagrant.py b/contrib/inventory/vagrant.py index 7f6dc925e8..7f6dc925e8 100755 --- a/plugins/inventory/vagrant.py +++ b/contrib/inventory/vagrant.py diff --git a/plugins/inventory/vbox.py b/contrib/inventory/vbox.py index ff31785d7e..ff31785d7e 100755 --- a/plugins/inventory/vbox.py +++ b/contrib/inventory/vbox.py diff --git a/plugins/inventory/vmware.ini b/contrib/inventory/vmware.ini index 5097735fd0..5097735fd0 100644 --- a/plugins/inventory/vmware.ini +++ b/contrib/inventory/vmware.ini diff --git a/plugins/inventory/vmware.py b/contrib/inventory/vmware.py index 1d533a5e15..1d533a5e15 100755 --- a/plugins/inventory/vmware.py +++ b/contrib/inventory/vmware.py diff --git a/plugins/inventory/windows_azure.ini b/contrib/inventory/windows_azure.ini index 133a5e5ff6..133a5e5ff6 100644 --- a/plugins/inventory/windows_azure.ini +++ b/contrib/inventory/windows_azure.ini diff --git a/plugins/inventory/windows_azure.py b/contrib/inventory/windows_azure.py index 1302967907..1302967907 100755 --- a/plugins/inventory/windows_azure.py +++ b/contrib/inventory/windows_azure.py diff --git a/plugins/inventory/zabbix.ini b/contrib/inventory/zabbix.ini index 618c2b9fe8..618c2b9fe8 100644 --- a/plugins/inventory/zabbix.ini +++ b/contrib/inventory/zabbix.ini diff --git a/plugins/inventory/zabbix.py b/contrib/inventory/zabbix.py index 2bc1e2e1cc..2bc1e2e1cc 100755 --- a/plugins/inventory/zabbix.py +++ b/contrib/inventory/zabbix.py diff --git a/plugins/inventory/zone.py b/contrib/inventory/zone.py index 163912c7f4..163912c7f4 100755 --- a/plugins/inventory/zone.py +++ b/contrib/inventory/zone.py diff --git a/lib/ansible/plugins/callback/log_plays.py b/lib/ansible/plugins/callback/log_plays.py new file mode 100644 index 0000000000..65036e6763 --- /dev/null +++ b/lib/ansible/plugins/callback/log_plays.py @@ -0,0 +1,85 @@ +# (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 os +import time +import json + +from ansible.plugins.callback import CallbackBase + +# NOTE: in Ansible 1.2 or later general logging is available without +# this plugin, just set ANSIBLE_LOG_PATH as an environment variable +# or log_path in the DEFAULTS section of your ansible configuration +# file. This callback is an example of per hosts logging for those +# that want it. + + +class CallbackModule(CallbackBase): + """ + logs playbook results, per host, in /var/log/ansible/hosts + """ + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'notification' + + TIME_FORMAT="%b %d %Y %H:%M:%S" + MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n" + + def __init__(self, display): + + super(CallbackModule, self).__init__(display) + + if not os.path.exists("/var/log/ansible/hosts"): + os.makedirs("/var/log/ansible/hosts") + + def log(self, host, category, data): + if type(data) == dict: + if 'verbose_override' in data: + # avoid logging extraneous data from facts + data = 'omitted' + else: + data = data.copy() + invocation = data.pop('invocation', None) + data = json.dumps(data) + if invocation is not None: + data = json.dumps(invocation) + " => %s " % data + + path = os.path.join("/var/log/ansible/hosts", host) + now = time.strftime(self.TIME_FORMAT, time.localtime()) + fd = open(path, "a") + fd.write(self.MSG_FORMAT % dict(now=now, category=category, data=data)) + fd.close() + + def runner_on_failed(self, host, res, ignore_errors=False): + self.log(host, 'FAILED', res) + + def runner_on_ok(self, host, res): + self.log(host, 'OK', res) + + def runner_on_skipped(self, host, item=None): + self.log(host, 'SKIPPED', '...') + + def runner_on_unreachable(self, host, res): + self.log(host, 'UNREACHABLE', res) + + def runner_on_async_failed(self, host, res, jid): + self.log(host, 'ASYNC_FAILED', res) + + def playbook_on_import_for_host(self, host, imported_file): + self.log(host, 'IMPORTED', imported_file) + + def playbook_on_not_import_for_host(self, host, missing_file): + self.log(host, 'NOTIMPORTED', missing_file) diff --git a/plugins/callbacks/osx_say.py b/lib/ansible/plugins/callback/osx_say.py index 174a03300f..bb785b3872 100644 --- a/plugins/callbacks/osx_say.py +++ b/lib/ansible/plugins/callback/osx_say.py @@ -19,87 +19,69 @@ 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" -def say(msg, voice): - subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)]) - -class CallbackModule(object): +class CallbackModule(CallbackBase): """ makes Ansible much more exciting on OS X. """ - def __init__(self): + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'notification' + + def __init__(self, display): + + super(CallbackModule, self).__init__(display) + # 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__)) + self._display.warning("%s does not exist, plugin %s disabled" % (SAY_CMD, os.path.basename(__file__)) ) - def on_any(self, *args, **kwargs): - pass + def say(self, msg, voice): + subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)]) def runner_on_failed(self, host, res, ignore_errors=False): - say("Failure on host %s" % host, FAILED_VOICE) + self.say("Failure on host %s" % host, FAILED_VOICE) def runner_on_ok(self, host, res): - say("pew", LASER_VOICE) + self.say("pew", LASER_VOICE) def runner_on_skipped(self, host, item=None): - say("pew", LASER_VOICE) + self.say("pew", LASER_VOICE) 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 + self.say("Failure on host %s" % host, FAILED_VOICE) def runner_on_async_ok(self, host, res, jid): - say("pew", LASER_VOICE) + self.say("pew", LASER_VOICE) def runner_on_async_failed(self, host, res, jid): - say("Failure on host %s" % host, FAILED_VOICE) + self.say("Failure on host %s" % host, FAILED_VOICE) def playbook_on_start(self): - say("Running Playbook", REGULAR_VOICE) + self.say("Running Playbook", REGULAR_VOICE) def playbook_on_notify(self, host, handler): - say("pew", LASER_VOICE) - - def playbook_on_no_hosts_matched(self): - pass - - def playbook_on_no_hosts_remaining(self): - pass + self.say("pew", LASER_VOICE) def playbook_on_task_start(self, name, is_conditional): if not is_conditional: - say("Starting task: %s" % name, REGULAR_VOICE) + self.say("Starting task: %s" % name, REGULAR_VOICE) else: - say("Notifying task: %s" % name, REGULAR_VOICE) - - def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None): - pass + self.say("Notifying task: %s" % name, REGULAR_VOICE) 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 + self.say("Gathering facts", REGULAR_VOICE) def playbook_on_play_start(self, name): - say("Starting play: %s" % name, HAPPY_VOICE) + self.say("Starting play: %s" % name, HAPPY_VOICE) def playbook_on_stats(self, stats): - say("Play complete", HAPPY_VOICE) - + self.say("Play complete", HAPPY_VOICE) diff --git a/plugins/callbacks/syslog_json.py b/lib/ansible/plugins/callback/syslog_json.py index 2e339e96ae..978a4d719a 100644 --- a/plugins/callbacks/syslog_json.py +++ b/lib/ansible/plugins/callback/syslog_json.py @@ -6,7 +6,9 @@ import logging.handlers import socket -class CallbackModule(object): +from ansible.plugins.callback import CallbackBase + +class CallbackModule(CallbackBase): """ logs ansible-playbook and ansible runs to a syslog server in json format make sure you have in ansible.cfg: @@ -17,8 +19,13 @@ class CallbackModule(object): SYSLOG_SERVER (optional): defaults to localhost SYSLOG_PORT (optional): defaults to 514 """ + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'aggregate' + + def __init__(self, display): + + super(CallbackModule, self).__init__(display) - def __init__(self): self.logger = logging.getLogger('ansible logger') self.logger.setLevel(logging.DEBUG) @@ -30,8 +37,6 @@ class CallbackModule(object): self.logger.addHandler(self.handler) self.hostname = socket.gethostname() - def on_any(self, *args, **kwargs): - pass def runner_on_failed(self, host, res, ignore_errors=False): self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname,host,json.dumps(res, sort_keys=True))) @@ -45,47 +50,11 @@ class CallbackModule(object): def runner_on_unreachable(self, host, res): self.logger.error('%s ansible-command: task execution UNREACHABLE; host: %s; message: %s' % (self.hostname,host,json.dumps(res, sort_keys=True))) - def runner_on_no_hosts(self): - pass - - def runner_on_async_poll(self, host, res): - pass - - def runner_on_async_ok(self, host, res): - pass - def runner_on_async_failed(self, host, res): self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname,host,json.dumps(res, sort_keys=True))) - def playbook_on_start(self): - pass - - def playbook_on_notify(self, host, handler): - pass - - def playbook_on_no_hosts_matched(self): - pass - - def playbook_on_no_hosts_remaining(self): - pass - - def playbook_on_task_start(self, name, is_conditional): - pass - - def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None): - pass - - def playbook_on_setup(self): - pass - def playbook_on_import_for_host(self, host, imported_file): self.logger.info('%s ansible-command: playbook IMPORTED; host: %s; message: %s' % (self.hostname,host,json.dumps(res, sort_keys=True))) def playbook_on_not_import_for_host(self, host, missing_file): self.logger.info('%s ansible-command: playbook NOT IMPORTED; host: %s; message: %s' % (self.hostname,host,json.dumps(res, sort_keys=True))) - - def playbook_on_play_start(self, name): - pass - - def playbook_on_stats(self, stats): - pass diff --git a/plugins/README.md b/plugins/README.md deleted file mode 100644 index 8d705372a5..0000000000 --- a/plugins/README.md +++ /dev/null @@ -1,35 +0,0 @@ -ansible-plugins -=============== - -You can extend ansible with optional callback and connection plugins. - -callbacks -========= - -Callbacks can be used to add logging or monitoring capability, or just make -interesting sound effects. - -Drop callback plugins in your ansible/lib/callback_plugins/ directory. - -connections -=========== - -Connection plugins allow ansible to talk over different protocols. - -Drop connection plugins in your ansible/lib/runner/connection_plugins/ directory. - -inventory -========= - -Inventory plugins allow you to store your hosts, groups, and variables in any way -you like. Examples include discovering inventory from EC2 or pulling it from -Cobbler. These could also be used to interface with LDAP or database. - -chmod +x an inventory plugin and either name it /etc/ansible/hosts or use ansible -with -i to designate the path to the plugin. - -contributions welcome -===================== - -Send in pull requests to add plugins of your own. The sky is the limit! - diff --git a/plugins/callbacks/log_plays.py b/plugins/callbacks/log_plays.py deleted file mode 100644 index dbe16b312c..0000000000 --- a/plugins/callbacks/log_plays.py +++ /dev/null @@ -1,116 +0,0 @@ -# (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 os -import time -import json - -# NOTE: in Ansible 1.2 or later general logging is available without -# this plugin, just set ANSIBLE_LOG_PATH as an environment variable -# or log_path in the DEFAULTS section of your ansible configuration -# file. This callback is an example of per hosts logging for those -# that want it. - -TIME_FORMAT="%b %d %Y %H:%M:%S" -MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n" - -if not os.path.exists("/var/log/ansible/hosts"): - os.makedirs("/var/log/ansible/hosts") - -def log(host, category, data): - if type(data) == dict: - if 'verbose_override' in data: - # avoid logging extraneous data from facts - data = 'omitted' - else: - data = data.copy() - invocation = data.pop('invocation', None) - data = json.dumps(data) - if invocation is not None: - data = json.dumps(invocation) + " => %s " % data - - path = os.path.join("/var/log/ansible/hosts", host) - now = time.strftime(TIME_FORMAT, time.localtime()) - fd = open(path, "a") - fd.write(MSG_FORMAT % dict(now=now, category=category, data=data)) - fd.close() - -class CallbackModule(object): - """ - logs playbook results, per host, in /var/log/ansible/hosts - """ - - def on_any(self, *args, **kwargs): - pass - - def runner_on_failed(self, host, res, ignore_errors=False): - log(host, 'FAILED', res) - - def runner_on_ok(self, host, res): - log(host, 'OK', res) - - def runner_on_skipped(self, host, item=None): - log(host, 'SKIPPED', '...') - - def runner_on_unreachable(self, host, res): - log(host, 'UNREACHABLE', res) - - 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): - pass - - def runner_on_async_failed(self, host, res, jid): - log(host, 'ASYNC_FAILED', res) - - def playbook_on_start(self): - pass - - def playbook_on_notify(self, host, handler): - pass - - def playbook_on_no_hosts_matched(self): - pass - - def playbook_on_no_hosts_remaining(self): - pass - - def playbook_on_task_start(self, name, is_conditional): - pass - - def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None): - pass - - def playbook_on_setup(self): - pass - - def playbook_on_import_for_host(self, host, imported_file): - log(host, 'IMPORTED', imported_file) - - def playbook_on_not_import_for_host(self, host, missing_file): - log(host, 'NOTIMPORTED', missing_file) - - def playbook_on_play_start(self, name): - pass - - def playbook_on_stats(self, stats): - pass - @@ -25,7 +25,7 @@ setup(name='ansible', package_dir={ '': 'lib' }, packages=find_packages('lib'), package_data={ - '': ['module_utils/*.ps1', 'modules/core/windows/*.ps1', 'modules/extras/windows/*.ps1'], + '': ['module_utils/*.ps1', 'modules/core/windows/*.ps1', 'modules/extras/windows/*.ps1', 'contrib/README.md', 'contrib/inventory/*'], }, scripts=[ 'bin/ansible', |