summaryrefslogtreecommitdiff
path: root/global/overlay/etc/puppet/cosmos_enc.py
blob: 63c3a666555f45e274ccddfa3d3d909153569b9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python

import sys
import yaml
import os
import re

rules_path = os.environ.get("COSMOS_RULES_PATH","/etc/puppet")

node_name = sys.argv[1]

rules = 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.load(fd))

classes = dict()
for reg,cls in rules.iteritems():
   if re.search(reg,node_name):
      classes.update(cls)

print yaml.dump(dict(classes=classes))