mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add include support to the configs
This commit is contained in:
parent
26bbd93d0a
commit
a54a6145dc
@ -3,6 +3,7 @@ All salt configuration loading and defaults should be in this module
|
||||
'''
|
||||
|
||||
# Import python modules
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
@ -52,7 +53,7 @@ def load_config(opts, path, env_var):
|
||||
# If the configuration file is missing, attempt to copy the template,
|
||||
# after removing the first header line.
|
||||
if not os.path.isfile(path):
|
||||
template = "%s.template" % path
|
||||
template = '{0}.template'.format(path)
|
||||
if os.path.isfile(template):
|
||||
with open(path, 'w') as out:
|
||||
with open(template, 'r') as f:
|
||||
@ -78,6 +79,34 @@ def load_config(opts, path, env_var):
|
||||
log.debug('Missing configuration file: {0}'.format(path))
|
||||
|
||||
|
||||
def include_config(opts, orig_path):
|
||||
'''
|
||||
Parses an extra configuration file specified in an include list in the
|
||||
main config file.
|
||||
'''
|
||||
include = opts.get('include', [])
|
||||
if isinstance(include, basestring):
|
||||
include = [include]
|
||||
for path in include:
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.join(os.path.dirname(orig_path), path)
|
||||
for fn_ in glob.glob(path):
|
||||
try:
|
||||
conf_opts = yaml.safe_load(open(fn_, 'r'))
|
||||
if conf_opts is None:
|
||||
# The config file is empty and the yaml.load returned None
|
||||
conf_opts = {}
|
||||
else:
|
||||
# allow using numeric ids: convert int to string
|
||||
if 'id' in conf_opts:
|
||||
conf_opts['id'] = str(conf_opts['id'])
|
||||
opts.update(conf_opts)
|
||||
except Exception, e:
|
||||
msg = 'Error parsing configuration file: {0} - {1}'
|
||||
log.warn(msg.format(fn_, e))
|
||||
return opts
|
||||
|
||||
|
||||
def prepend_root_dir(opts, path_options):
|
||||
'''
|
||||
Prepends the options that represent filesystem paths with value of the
|
||||
@ -127,6 +156,9 @@ def minion_config(path):
|
||||
|
||||
load_config(opts, path, 'SALT_MINION_CONFIG')
|
||||
|
||||
if 'include' in opts:
|
||||
opts = include_config(opts, path)
|
||||
|
||||
opts['master_ip'] = dns_check(opts['master'])
|
||||
|
||||
opts['master_uri'] = 'tcp://' + opts['master_ip'] + ':'\
|
||||
@ -186,6 +218,9 @@ def master_config(path):
|
||||
|
||||
load_config(opts, path, 'SALT_MASTER_CONFIG')
|
||||
|
||||
if 'include' in opts:
|
||||
opts = include_config(opts, path)
|
||||
|
||||
opts['aes'] = salt.crypt.Crypticle.generate_key_string()
|
||||
|
||||
# Prepend root_dir to other paths
|
||||
|
Loading…
Reference in New Issue
Block a user