Merge branch 'master' of /git/ansible

This commit is contained in:
4 changed files with 103 additions and 125 deletions

View file

@ -0,0 +1,79 @@
# (C) 2012, Michael DeHaan, <michael.dehaan@gmail.com>
# based on the log_plays example
# skvidal@fedoraproject.org
# rbean@redhat.com
# 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 pwd
import fedmsg
import fedmsg.config
def getlogin():
try:
user = os.getlogin()
except OSError, e:
user = pwd.getpwuid(os.geteuid())[0]
return user
class CallbackModule(object):
""" Publish playbook starts and stops to fedmsg. """
playbook = None
def __init__(self):
config = fedmsg.config.load_config()
config.update(dict(
name='relay_inbound',
cert_prefix='shell',
active=True,
))
fedmsg.init(**config)
def playbook_on_play_start(self, pattern):
# This gets called once for each play.. but we just issue a message once
# for the first one. One per "playbook"
play = getattr(self, 'play', None)
if play:
# figure out where the playbook FILE is
path = os.path.abspath(play.playbook.filename)
if not self.playbook:
fedmsg.publish(
modname="ansible", topic="playbook.start",
msg=dict(
playbook=path,
userid=getlogin(),
extra_vars=play.playbook.extra_vars,
inventory=play.playbook.inventory.host_list,
playbook_checksum=play.playbook.check,
check=play.playbook.check,
),
)
self.playbook = path
def playbook_on_stats(self, stats):
results = dict([(h, stats.summarize(h)) for h in stats.processed])
fedmsg.publish(
modname="ansible", topic="playbook.complete",
msg=dict(
playbook=self.playbook,
userid=getlogin(),
results=results,
),
)

View file

@ -1,81 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) 2013, Ralph Bean <rbean@redhat.com>
# LGPLv2+
#
# You can pass this action an arbitrary number of kw arguments which will be
# used to make up the main message body (json).
#
# Dedicated to Seth Vidal. This was his idea.
DOCUMENTATION = '''
---
module: fedmsg
short_description: Publish a message to fedmsg.
description:
- Send a message to a fedmsg-relay daemon.
options:
topic:
description:
- The short portion of the message topic.
required: false
default: log
modname:
description:
- The modname portion of the message topic.
required: false
default: ansible
requirements: [ fedmsg ]
author: Ralph Bean
'''
EXAMPLES = '''
- fedmsg: msg="Testing this out"
- local_action: fedmsg
topic="run.complete"
msg="{{ ansible_date_time.iso8601 }}"
'''
import fedmsg
import fedmsg.config
def main():
module = AnsibleModule(
argument_spec=dict(
topic=dict(default="log"),
modname=dict(default="ansible"),
cert_prefix=dict(default="ansible"),
),
check_invalid_arguments=False,
supports_check_mode=True
)
topic = module.params.pop('topic')
modname = module.params.pop('modname')
cert_prefix = module.params.pop('cert_prefix')
try:
config = fedmsg.config.load_config()
config.update(dict(
name='relay_inbound',
cert_prefix=cert_prefix,
active=True,
))
fedmsg.init(**config)
except Exception, e:
module.fail_json(msg="unable to initialize fedmsg: %s" % e)
try:
fedmsg.publish(modname=modname, topic=topic, msg=module.params)
except Exception, e:
module.fail_json(msg="unable to send to fedmsg: %s" % e)
module.exit_json(changed=False, **module.params)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()

View file

@ -3,16 +3,6 @@
# NOTE: make sure there is room/space for this server on the vmhost
# NOTE: most of these vars come from group_vars/badges-web* or from hostvars
- name: emit a fedmsg message that we are done
hosts: badges-web;badges-web-stg
user: root
gather_facts: False
tasks:
- local_action: fedmsg
cert_prefix="shell"
topic="playbook.start"
msg="just a test that we are starting"
- name: make badges-web server
hosts: badges-web;badges-web-stg
user: root
@ -61,13 +51,3 @@
handlers:
- include: $handlers/restart_services.yml
- name: emit a fedmsg message that we are done
hosts: badges-web;badges-web-stg
user: root
gather_facts: False
tasks:
- local_action: fedmsg
cert_prefix="shell"
topic="playbook.complete"
msg="just a test that we are completing"