CSC Ansible Playbooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ansible-playbooks/roles/load-balancer/files/haproxy/genconfig.py

37 lines
974 B

#!/usr/bin/env python
from __future__ import print_function
import os, sys
from optparse import OptionParser
import yaml
from mako.template import Template
import pprint
def main():
# Arguments
parser = OptionParser()
parser.add_option('-c', '--config', dest='config', default='config.yml',
help='Configuration file', metavar="FILE")
parser.add_option('-t', '--template', dest='template', default='haproxy.cfg.mako',
help='haproxy.cfg Mako template')
(options, args) = parser.parse_args()
try:
config = yaml.load(open(options.config, 'r'))
except Exception as e:
print(e, file=sys.stderr)
config = None
if not config or type(config) != dict:
print('Unable to load configuration: "{}"'.format(options.config), file=sys.stderr)
sys.exit(-1)
print(Template(filename=options.template).render(config=config))
if __name__ == '__main__':
main()