remove 'make db'

The db-file, essentially providing reverse lookup of classes to host
names, is only used by some Nagios configuration instances and causes
continuing operational headaches in those ops-repos.

It should be kept/refactored to only apply to the monitoring hosts in
the cases where it is used, but we don't want any new ops-repos to use
it hence it should be removed from upstream multiverse.
This commit is contained in:
Fredrik Thulin 2023-02-07 14:21:29 +01:00
parent 46f4fc6d33
commit c400bba97d
No known key found for this signature in database
GPG key ID: 2707330D4030CCAD
2 changed files with 27 additions and 57 deletions

View file

@ -1,49 +0,0 @@
import os
import yaml
import re
def _all_hosts():
return filter(lambda fn: '.' in fn and not fn.startswith('.') and os.path.isdir(fn),os.listdir("."))
def _load_db():
rules = dict()
rules_file = "cosmos-rules.yaml";
if os.path.exists(rules_file):
with open(rules_file) as fd:
rules.update(yaml.load(fd))
all_hosts = _all_hosts()
members = dict()
for node_name in all_hosts:
for reg,cls in rules.iteritems():
if re.match(reg,node_name):
for cls_name in cls.keys():
h = members.get(cls_name,[])
h.append(node_name)
members[cls_name] = h
members['all'] = all_hosts
classes = dict()
for node_name in all_hosts:
node_classes = dict()
for reg,cls in rules.iteritems():
if re.match(reg,node_name):
node_classes.update(cls)
classes[node_name] = node_classes
# Sort member lists for a more easy to read diff
for cls in members.keys():
members[cls].sort()
return dict(classes=classes,members=members)
_db = None
def cosmos_db():
global _db
if _db is None:
_db = _load_db()
return _db
if __name__ == '__main__':
print yaml.dump(cosmos_db())

View file

@ -1,18 +1,37 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#
# Puppet 'External Node Classifier' to tell puppet what classes to apply to this node.
#
# Docs: https://puppet.com/docs/puppet/5.3/nodes_external.html
#
import sys
import yaml
import os import os
import re import re
import sys
import yaml
rules_path = os.environ.get("COSMOS_RULES_PATH", "/etc/puppet")
node_name = sys.argv[1] node_name = sys.argv[1]
db_file = os.environ.get("COSMOS_ENC_DB","/etc/puppet/cosmos-db.yaml") rules = dict()
db = dict(classes=dict()) for p in rules_path.split(":"):
rules_file = os.path.join(p, "cosmos-rules.yaml")
if os.path.exists(rules_file):
with open(rules_file) as fd:
rules.update(yaml.safe_load(fd))
if os.path.exists(db_file): found = False
with open(db_file) as fd: classes = dict()
db.update(yaml.load(fd)) for reg, cls in rules.items():
if re.search(reg, node_name):
classes.update(cls)
found = True
print(yaml.dump(dict(classes=db['classes'].get(node_name,dict()),parameters=dict(roles=db.get('members',[]))))) if not found:
sys.stderr.write(f"{sys.argv[0]}: {node_name} not found in cosmos-rules.yaml\n")
print("---\n" + yaml.dump(dict(classes=classes)))
sys.exit(0)