From d0c6d2ff1c9f1bcf7c6a1fc717daaeffa5f38b48 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 8 Jul 2015 20:37:17 -0400 Subject: [PATCH] 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 --- contrib/README.md | 17 +++ {plugins => contrib}/inventory/abiquo.ini | 0 {plugins => contrib}/inventory/abiquo.py | 0 .../inventory/apache-libcloud.py | 0 {plugins => contrib}/inventory/cloudstack.ini | 0 {plugins => contrib}/inventory/cloudstack.py | 0 {plugins => contrib}/inventory/cobbler.ini | 0 {plugins => contrib}/inventory/cobbler.py | 0 {plugins => contrib}/inventory/collins.ini | 0 {plugins => contrib}/inventory/collins.py | 0 {plugins => contrib}/inventory/consul.ini | 0 {plugins => contrib}/inventory/consul_io.py | 0 .../inventory/digital_ocean.ini | 0 .../inventory/digital_ocean.py | 0 {plugins => contrib}/inventory/docker.py | 0 {plugins => contrib}/inventory/docker.yml | 0 {plugins => contrib}/inventory/ec2.ini | 0 {plugins => contrib}/inventory/ec2.py | 0 {plugins => contrib}/inventory/fleet.py | 0 {plugins => contrib}/inventory/freeipa.py | 0 {plugins => contrib}/inventory/gce.ini | 0 {plugins => contrib}/inventory/gce.py | 0 {plugins => contrib}/inventory/jail.py | 0 {plugins => contrib}/inventory/landscape.py | 0 {plugins => contrib}/inventory/libcloud.ini | 0 {plugins => contrib}/inventory/libvirt_lxc.py | 0 {plugins => contrib}/inventory/linode.ini | 0 {plugins => contrib}/inventory/linode.py | 0 {plugins => contrib}/inventory/nova.ini | 0 {plugins => contrib}/inventory/nova.py | 0 {plugins => contrib}/inventory/openshift.py | 0 {plugins => contrib}/inventory/openstack.py | 0 {plugins => contrib}/inventory/openstack.yml | 0 {plugins => contrib}/inventory/ovirt.ini | 0 {plugins => contrib}/inventory/ovirt.py | 0 {plugins => contrib}/inventory/rax.ini | 0 {plugins => contrib}/inventory/rax.py | 0 {plugins => contrib}/inventory/serf.py | 0 {plugins => contrib}/inventory/softlayer.py | 0 {plugins => contrib}/inventory/spacewalk.py | 0 {plugins => contrib}/inventory/ssh_config.py | 0 {plugins => contrib}/inventory/vagrant.py | 0 {plugins => contrib}/inventory/vbox.py | 0 {plugins => contrib}/inventory/vmware.ini | 0 {plugins => contrib}/inventory/vmware.py | 0 .../inventory/windows_azure.ini | 0 .../inventory/windows_azure.py | 0 {plugins => contrib}/inventory/zabbix.ini | 0 {plugins => contrib}/inventory/zabbix.py | 0 {plugins => contrib}/inventory/zone.py | 0 lib/ansible/plugins/callback/log_plays.py | 85 +++++++++++++ .../ansible/plugins/callback}/osx_say.py | 70 ++++------- .../ansible/plugins/callback}/syslog_json.py | 49 ++------ plugins/README.md | 35 ------ plugins/callbacks/log_plays.py | 116 ------------------ setup.py | 2 +- 56 files changed, 138 insertions(+), 236 deletions(-) create mode 100644 contrib/README.md rename {plugins => contrib}/inventory/abiquo.ini (100%) rename {plugins => contrib}/inventory/abiquo.py (100%) rename {plugins => contrib}/inventory/apache-libcloud.py (100%) rename {plugins => contrib}/inventory/cloudstack.ini (100%) rename {plugins => contrib}/inventory/cloudstack.py (100%) rename {plugins => contrib}/inventory/cobbler.ini (100%) rename {plugins => contrib}/inventory/cobbler.py (100%) rename {plugins => contrib}/inventory/collins.ini (100%) rename {plugins => contrib}/inventory/collins.py (100%) rename {plugins => contrib}/inventory/consul.ini (100%) rename {plugins => contrib}/inventory/consul_io.py (100%) rename {plugins => contrib}/inventory/digital_ocean.ini (100%) rename {plugins => contrib}/inventory/digital_ocean.py (100%) rename {plugins => contrib}/inventory/docker.py (100%) rename {plugins => contrib}/inventory/docker.yml (100%) rename {plugins => contrib}/inventory/ec2.ini (100%) rename {plugins => contrib}/inventory/ec2.py (100%) rename {plugins => contrib}/inventory/fleet.py (100%) rename {plugins => contrib}/inventory/freeipa.py (100%) rename {plugins => contrib}/inventory/gce.ini (100%) rename {plugins => contrib}/inventory/gce.py (100%) rename {plugins => contrib}/inventory/jail.py (100%) rename {plugins => contrib}/inventory/landscape.py (100%) rename {plugins => contrib}/inventory/libcloud.ini (100%) rename {plugins => contrib}/inventory/libvirt_lxc.py (100%) rename {plugins => contrib}/inventory/linode.ini (100%) rename {plugins => contrib}/inventory/linode.py (100%) rename {plugins => contrib}/inventory/nova.ini (100%) rename {plugins => contrib}/inventory/nova.py (100%) rename {plugins => contrib}/inventory/openshift.py (100%) rename {plugins => contrib}/inventory/openstack.py (100%) rename {plugins => contrib}/inventory/openstack.yml (100%) rename {plugins => contrib}/inventory/ovirt.ini (100%) rename {plugins => contrib}/inventory/ovirt.py (100%) rename {plugins => contrib}/inventory/rax.ini (100%) rename {plugins => contrib}/inventory/rax.py (100%) rename {plugins => contrib}/inventory/serf.py (100%) rename {plugins => contrib}/inventory/softlayer.py (100%) rename {plugins => contrib}/inventory/spacewalk.py (100%) rename {plugins => contrib}/inventory/ssh_config.py (100%) rename {plugins => contrib}/inventory/vagrant.py (100%) rename {plugins => contrib}/inventory/vbox.py (100%) rename {plugins => contrib}/inventory/vmware.ini (100%) rename {plugins => contrib}/inventory/vmware.py (100%) rename {plugins => contrib}/inventory/windows_azure.ini (100%) rename {plugins => contrib}/inventory/windows_azure.py (100%) rename {plugins => contrib}/inventory/zabbix.ini (100%) rename {plugins => contrib}/inventory/zabbix.py (100%) rename {plugins => contrib}/inventory/zone.py (100%) create mode 100644 lib/ansible/plugins/callback/log_plays.py rename {plugins/callbacks => lib/ansible/plugins/callback}/osx_say.py (54%) rename {plugins/callbacks => lib/ansible/plugins/callback}/syslog_json.py (72%) delete mode 100644 plugins/README.md delete mode 100644 plugins/callbacks/log_plays.py 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 similarity index 100% rename from plugins/inventory/abiquo.ini rename to contrib/inventory/abiquo.ini diff --git a/plugins/inventory/abiquo.py b/contrib/inventory/abiquo.py similarity index 100% rename from plugins/inventory/abiquo.py rename to contrib/inventory/abiquo.py diff --git a/plugins/inventory/apache-libcloud.py b/contrib/inventory/apache-libcloud.py similarity index 100% rename from plugins/inventory/apache-libcloud.py rename to contrib/inventory/apache-libcloud.py diff --git a/plugins/inventory/cloudstack.ini b/contrib/inventory/cloudstack.ini similarity index 100% rename from plugins/inventory/cloudstack.ini rename to contrib/inventory/cloudstack.ini diff --git a/plugins/inventory/cloudstack.py b/contrib/inventory/cloudstack.py similarity index 100% rename from plugins/inventory/cloudstack.py rename to contrib/inventory/cloudstack.py diff --git a/plugins/inventory/cobbler.ini b/contrib/inventory/cobbler.ini similarity index 100% rename from plugins/inventory/cobbler.ini rename to contrib/inventory/cobbler.ini diff --git a/plugins/inventory/cobbler.py b/contrib/inventory/cobbler.py similarity index 100% rename from plugins/inventory/cobbler.py rename to contrib/inventory/cobbler.py diff --git a/plugins/inventory/collins.ini b/contrib/inventory/collins.ini similarity index 100% rename from plugins/inventory/collins.ini rename to contrib/inventory/collins.ini diff --git a/plugins/inventory/collins.py b/contrib/inventory/collins.py similarity index 100% rename from plugins/inventory/collins.py rename to contrib/inventory/collins.py diff --git a/plugins/inventory/consul.ini b/contrib/inventory/consul.ini similarity index 100% rename from plugins/inventory/consul.ini rename to contrib/inventory/consul.ini diff --git a/plugins/inventory/consul_io.py b/contrib/inventory/consul_io.py similarity index 100% rename from plugins/inventory/consul_io.py rename to contrib/inventory/consul_io.py diff --git a/plugins/inventory/digital_ocean.ini b/contrib/inventory/digital_ocean.ini similarity index 100% rename from plugins/inventory/digital_ocean.ini rename to contrib/inventory/digital_ocean.ini diff --git a/plugins/inventory/digital_ocean.py b/contrib/inventory/digital_ocean.py similarity index 100% rename from plugins/inventory/digital_ocean.py rename to contrib/inventory/digital_ocean.py diff --git a/plugins/inventory/docker.py b/contrib/inventory/docker.py similarity index 100% rename from plugins/inventory/docker.py rename to contrib/inventory/docker.py diff --git a/plugins/inventory/docker.yml b/contrib/inventory/docker.yml similarity index 100% rename from plugins/inventory/docker.yml rename to contrib/inventory/docker.yml diff --git a/plugins/inventory/ec2.ini b/contrib/inventory/ec2.ini similarity index 100% rename from plugins/inventory/ec2.ini rename to contrib/inventory/ec2.ini diff --git a/plugins/inventory/ec2.py b/contrib/inventory/ec2.py similarity index 100% rename from plugins/inventory/ec2.py rename to contrib/inventory/ec2.py diff --git a/plugins/inventory/fleet.py b/contrib/inventory/fleet.py similarity index 100% rename from plugins/inventory/fleet.py rename to contrib/inventory/fleet.py diff --git a/plugins/inventory/freeipa.py b/contrib/inventory/freeipa.py similarity index 100% rename from plugins/inventory/freeipa.py rename to contrib/inventory/freeipa.py diff --git a/plugins/inventory/gce.ini b/contrib/inventory/gce.ini similarity index 100% rename from plugins/inventory/gce.ini rename to contrib/inventory/gce.ini diff --git a/plugins/inventory/gce.py b/contrib/inventory/gce.py similarity index 100% rename from plugins/inventory/gce.py rename to contrib/inventory/gce.py diff --git a/plugins/inventory/jail.py b/contrib/inventory/jail.py similarity index 100% rename from plugins/inventory/jail.py rename to contrib/inventory/jail.py diff --git a/plugins/inventory/landscape.py b/contrib/inventory/landscape.py similarity index 100% rename from plugins/inventory/landscape.py rename to contrib/inventory/landscape.py diff --git a/plugins/inventory/libcloud.ini b/contrib/inventory/libcloud.ini similarity index 100% rename from plugins/inventory/libcloud.ini rename to contrib/inventory/libcloud.ini diff --git a/plugins/inventory/libvirt_lxc.py b/contrib/inventory/libvirt_lxc.py similarity index 100% rename from plugins/inventory/libvirt_lxc.py rename to contrib/inventory/libvirt_lxc.py diff --git a/plugins/inventory/linode.ini b/contrib/inventory/linode.ini similarity index 100% rename from plugins/inventory/linode.ini rename to contrib/inventory/linode.ini diff --git a/plugins/inventory/linode.py b/contrib/inventory/linode.py similarity index 100% rename from plugins/inventory/linode.py rename to contrib/inventory/linode.py diff --git a/plugins/inventory/nova.ini b/contrib/inventory/nova.ini similarity index 100% rename from plugins/inventory/nova.ini rename to contrib/inventory/nova.ini diff --git a/plugins/inventory/nova.py b/contrib/inventory/nova.py similarity index 100% rename from plugins/inventory/nova.py rename to contrib/inventory/nova.py diff --git a/plugins/inventory/openshift.py b/contrib/inventory/openshift.py similarity index 100% rename from plugins/inventory/openshift.py rename to contrib/inventory/openshift.py diff --git a/plugins/inventory/openstack.py b/contrib/inventory/openstack.py similarity index 100% rename from plugins/inventory/openstack.py rename to contrib/inventory/openstack.py diff --git a/plugins/inventory/openstack.yml b/contrib/inventory/openstack.yml similarity index 100% rename from plugins/inventory/openstack.yml rename to contrib/inventory/openstack.yml diff --git a/plugins/inventory/ovirt.ini b/contrib/inventory/ovirt.ini similarity index 100% rename from plugins/inventory/ovirt.ini rename to contrib/inventory/ovirt.ini diff --git a/plugins/inventory/ovirt.py b/contrib/inventory/ovirt.py similarity index 100% rename from plugins/inventory/ovirt.py rename to contrib/inventory/ovirt.py diff --git a/plugins/inventory/rax.ini b/contrib/inventory/rax.ini similarity index 100% rename from plugins/inventory/rax.ini rename to contrib/inventory/rax.ini diff --git a/plugins/inventory/rax.py b/contrib/inventory/rax.py similarity index 100% rename from plugins/inventory/rax.py rename to contrib/inventory/rax.py diff --git a/plugins/inventory/serf.py b/contrib/inventory/serf.py similarity index 100% rename from plugins/inventory/serf.py rename to contrib/inventory/serf.py diff --git a/plugins/inventory/softlayer.py b/contrib/inventory/softlayer.py similarity index 100% rename from plugins/inventory/softlayer.py rename to contrib/inventory/softlayer.py diff --git a/plugins/inventory/spacewalk.py b/contrib/inventory/spacewalk.py similarity index 100% rename from plugins/inventory/spacewalk.py rename to contrib/inventory/spacewalk.py diff --git a/plugins/inventory/ssh_config.py b/contrib/inventory/ssh_config.py similarity index 100% rename from plugins/inventory/ssh_config.py rename to contrib/inventory/ssh_config.py diff --git a/plugins/inventory/vagrant.py b/contrib/inventory/vagrant.py similarity index 100% rename from plugins/inventory/vagrant.py rename to contrib/inventory/vagrant.py diff --git a/plugins/inventory/vbox.py b/contrib/inventory/vbox.py similarity index 100% rename from plugins/inventory/vbox.py rename to contrib/inventory/vbox.py diff --git a/plugins/inventory/vmware.ini b/contrib/inventory/vmware.ini similarity index 100% rename from plugins/inventory/vmware.ini rename to contrib/inventory/vmware.ini diff --git a/plugins/inventory/vmware.py b/contrib/inventory/vmware.py similarity index 100% rename from plugins/inventory/vmware.py rename to contrib/inventory/vmware.py diff --git a/plugins/inventory/windows_azure.ini b/contrib/inventory/windows_azure.ini similarity index 100% rename from plugins/inventory/windows_azure.ini rename to contrib/inventory/windows_azure.ini diff --git a/plugins/inventory/windows_azure.py b/contrib/inventory/windows_azure.py similarity index 100% rename from plugins/inventory/windows_azure.py rename to contrib/inventory/windows_azure.py diff --git a/plugins/inventory/zabbix.ini b/contrib/inventory/zabbix.ini similarity index 100% rename from plugins/inventory/zabbix.ini rename to contrib/inventory/zabbix.ini diff --git a/plugins/inventory/zabbix.py b/contrib/inventory/zabbix.py similarity index 100% rename from plugins/inventory/zabbix.py rename to contrib/inventory/zabbix.py diff --git a/plugins/inventory/zone.py b/contrib/inventory/zone.py similarity index 100% rename from plugins/inventory/zone.py rename to 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, + +# 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 . + +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 similarity index 54% rename from plugins/callbacks/osx_say.py rename to 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 similarity index 72% rename from plugins/callbacks/syslog_json.py rename to 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, - -# 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 . - -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 - diff --git a/setup.py b/setup.py index 1f73836cbd..01ee94cfda 100644 --- a/setup.py +++ b/setup.py @@ -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',