ansible/filter_plugins/fedmsg.py

35 lines
1,010 B
Python
Raw Normal View History

import operator
def invert_fedmsg_policy(hosts, vars):
""" Given hostvars that map hosts -> topics, invert that
and return a dict that maps topics -> hosts.
Really, returns a list of tuples -- not a dict.
"""
2015-06-12 16:44:14 +00:00
return [('what', 'is going on')] # debugging, obviously.
inverted = {}
for host in vars:
prefix = '.'.join([vars[host]['fedmsg_prefix'],
vars[host]['fedmsg_env']])
fqdn = vars[host].get('fedmsg_fqdn', vars[host]['ansible_fqdn'])
2015-06-12 16:29:45 +00:00
for cert in vars[host]['fedmsg_certs']:
for topic in cert.get('can_send', []):
key = prefix + '.' + topic
inverted[key] = inverted.get(key, [])
inverted[key].append(cert['service'] + '-' + fqdn)
result = inverted.items()
result.sort(key=operator.itemgetter(0))
return result
2015-06-12 16:30:46 +00:00
class FilterModule(object):
def filters(self):
return {
"invert_fedmsg_policy": invert_fedmsg_policy,
2015-06-12 16:30:46 +00:00
}