Move services.json into ansible
This commit is contained in:
parent
6548019090
commit
3fed27b42f
11 changed files with 188 additions and 153 deletions
playbooks/filter_plugins
|
@ -1,17 +0,0 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'my_service_attributes': self.my_service_attributes,
|
||||
}
|
||||
|
||||
def my_service_attributes(self, services, my_services, attribute="name"):
|
||||
result = []
|
||||
for service in services:
|
||||
if service["name"] in my_services:
|
||||
if attribute in service:
|
||||
if type(service[attribute]) == list:
|
||||
result.extend(service[attribute])
|
||||
else:
|
||||
result.append(service[attribute])
|
||||
|
||||
return result
|
38
playbooks/filter_plugins/service_filters.py
Normal file
38
playbooks/filter_plugins/service_filters.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'my_service_attributes': self.my_service_attributes,
|
||||
'services_to_dnscontrol': self.services_to_dnscontrol,
|
||||
}
|
||||
|
||||
def my_service_attributes(self, services, host, attribute="name"):
|
||||
result = []
|
||||
for service in services:
|
||||
if service["host"] != host:
|
||||
continue
|
||||
if not attribute in service:
|
||||
continue
|
||||
|
||||
if type(service[attribute]) == list:
|
||||
result.extend(service[attribute])
|
||||
else:
|
||||
result.append(service[attribute])
|
||||
|
||||
return result
|
||||
|
||||
def services_to_dnscontrol(self, services):
|
||||
result = {}
|
||||
for service in services:
|
||||
for dns in service.get("dns", []):
|
||||
name = dns.get("name", service["name"])
|
||||
result[name] = {
|
||||
"target": dns["target"],
|
||||
"domain": dns["domain"],
|
||||
}
|
||||
|
||||
if "alias" in dns:
|
||||
result[name]["alias"] = dns["alias"]
|
||||
else:
|
||||
result[name]["host"] = service["host"]
|
||||
|
||||
return result
|
Loading…
Add table
Add a link
Reference in a new issue