2
0

Handle config opts not part of default config.

This commit is contained in:
Matthew Richardson 2016-08-22 11:22:08 +01:00
parent 39a329b693
commit 5abdaee5a2

View File

@ -4,7 +4,9 @@
{% set reserved_keys = ['master', 'minion', 'cloud', 'salt_cloud_certs'] -%} {% set reserved_keys = ['master', 'minion', 'cloud', 'salt_cloud_certs'] -%}
{% set cfg_salt = pillar.get('salt', {}) -%} {% set cfg_salt = pillar.get('salt', {}) -%}
{% set cfg_minion = cfg_salt.get('minion', {}) -%} {% set cfg_minion = cfg_salt.get('minion', {}) -%}
{% set default_keys = [] -%}
{%- macro get_config(configname, default_value) -%} {%- macro get_config(configname, default_value) -%}
{%- do default_keys.append(configname) %}
{%- if configname in cfg_minion -%} {%- if configname in cfg_minion -%}
{{ configname }}: {{ cfg_minion[configname]|json }} {{ configname }}: {{ cfg_minion[configname]|json }}
{%- elif configname in cfg_salt and configname not in reserved_keys -%} {%- elif configname in cfg_salt and configname not in reserved_keys -%}
@ -103,6 +105,7 @@ master:
# same machine but with different ids, this can be useful for salt compute # same machine but with different ids, this can be useful for salt compute
# clusters. # clusters.
{% if 'id' in cfg_minion -%} {% if 'id' in cfg_minion -%}
{%- do default_keys.append('id') %}
id: {{ cfg_minion['id'] }} id: {{ cfg_minion['id'] }}
{% else -%} {% else -%}
#id: #id:
@ -205,6 +208,7 @@ id: {{ cfg_minion['id'] }}
{{ get_config('ping_interval', '0') }} {{ get_config('ping_interval', '0') }}
{%- if 'mine_functions' in cfg_minion %} {%- if 'mine_functions' in cfg_minion %}
{%- do default_keys.append('mine_functions') %}
mine_functions: mine_functions:
{%- for func, args in cfg_minion['mine_functions'].items() %} {%- for func, args in cfg_minion['mine_functions'].items() %}
{{ func }}: {{ args }} {{ func }}: {{ args }}
@ -336,6 +340,7 @@ mine_functions:
# #
# Include a config file from some other path: # Include a config file from some other path:
{% if 'include' in cfg_minion -%} {% if 'include' in cfg_minion -%}
{%- do default_keys.append('include') %}
{% if isinstance(cfg_minion['include'], list) -%} {% if isinstance(cfg_minion['include'], list) -%}
include: include:
{% for include in cfg_minion['include'] -%} {% for include in cfg_minion['include'] -%}
@ -483,6 +488,7 @@ file_client: local
# - /srv/salt/prod/services # - /srv/salt/prod/services
# - /srv/salt/prod/states # - /srv/salt/prod/states
{% if 'file_roots' in cfg_minion -%} {% if 'file_roots' in cfg_minion -%}
{%- do default_keys.append('file_roots') %}
{{ file_roots(cfg_minion['file_roots']) }} {{ file_roots(cfg_minion['file_roots']) }}
{%- elif 'file_roots' in cfg_salt -%} {%- elif 'file_roots' in cfg_salt -%}
{{ file_roots(cfg_salt['file_roots']) }} {{ file_roots(cfg_salt['file_roots']) }}
@ -511,6 +517,7 @@ file_client: local
# - git # - git
# - roots # - roots
{% if 'fileserver_backend' in cfg_minion -%} {% if 'fileserver_backend' in cfg_minion -%}
{%- do default_keys.append('fileserver_backend') %}
fileserver_backend: fileserver_backend:
{%- for backend in cfg_minion['fileserver_backend'] %} {%- for backend in cfg_minion['fileserver_backend'] %}
- {{ backend }} - {{ backend }}
@ -570,6 +577,7 @@ fileserver_backend:
# Note: file:// repos will be treated as a remote, so refs you want used must # Note: file:// repos will be treated as a remote, so refs you want used must
# exist in that repo as *local* refs. # exist in that repo as *local* refs.
{% if 'gitfs_remotes' in cfg_minion -%} {% if 'gitfs_remotes' in cfg_minion -%}
{%- do default_keys.append('gitfs_remotes') %}
gitfs_remotes: gitfs_remotes:
{%- for remote in cfg_minion['gitfs_remotes'] %} {%- for remote in cfg_minion['gitfs_remotes'] %}
{%- if remote is iterable and remote is not string %} {%- if remote is iterable and remote is not string %}
@ -602,6 +610,7 @@ gitfs_remotes:
# The gitfs_env_whitelist and gitfs_env_blacklist parameters allow for greater # The gitfs_env_whitelist and gitfs_env_blacklist parameters allow for greater
# control over which branches/tags are exposed as fileserver environments. # control over which branches/tags are exposed as fileserver environments.
{% if 'gitfs_env_whitelist' in cfg_minion -%} {% if 'gitfs_env_whitelist' in cfg_minion -%}
{%- do default_keys.append('gitfs_env_whitelist') %}
gitfs_env_whitelist: gitfs_env_whitelist:
{%- for git_env in cfg_minion['gitfs_env_whitelist'] %} {%- for git_env in cfg_minion['gitfs_env_whitelist'] %}
- {{ git_env }} - {{ git_env }}
@ -613,6 +622,7 @@ gitfs_env_whitelist:
{% endif %} {% endif %}
{% if 'gitfs_env_blacklist' in cfg_minion -%} {% if 'gitfs_env_blacklist' in cfg_minion -%}
{%- do default_keys.append('gitfs_env_blacklist') %}
gitfs_env_blacklist: gitfs_env_blacklist:
{%- for git_env in cfg_minion['gitfs_env_blacklist'] %} {%- for git_env in cfg_minion['gitfs_env_blacklist'] %}
- {{ git_env }} - {{ git_env }}
@ -629,6 +639,7 @@ gitfs_env_blacklist:
# this is the case, and pillar data is defined, then the pillar_roots need to # this is the case, and pillar data is defined, then the pillar_roots need to
# also be configured on the minion: # also be configured on the minion:
{% if 'pillar_roots' in cfg_minion -%} {% if 'pillar_roots' in cfg_minion -%}
{%- do default_keys.append('pillar_roots') %}
pillar_roots: pillar_roots:
{%- for name, roots in cfg_minion['pillar_roots']|dictsort %} {%- for name, roots in cfg_minion['pillar_roots']|dictsort %}
{{ name }}: {{ name }}:
@ -651,6 +662,7 @@ pillar_roots:
{%- endif %} {%- endif %}
{% if 'ext_pillar' in cfg_minion %} {% if 'ext_pillar' in cfg_minion %}
{%- do default_keys.append('ext_pillar') %}
ext_pillar: ext_pillar:
{%- for pillar in cfg_minion['ext_pillar'] -%} {%- for pillar in cfg_minion['ext_pillar'] -%}
{%- for key in pillar -%} {%- for key in pillar -%}
@ -930,6 +942,7 @@ ext_pillar:
{%- if 'module_config' in cfg_minion %} {%- if 'module_config' in cfg_minion %}
{%- do default_keys.append('module_config') %}
{%- for modkey, modval in cfg_minion.module_config.items() %} {%- for modkey, modval in cfg_minion.module_config.items() %}
{{ modkey }}: {{ modval }} {{ modkey }}: {{ modval }}
{%- endfor %} {%- endfor %}
@ -993,6 +1006,7 @@ ext_pillar:
{{ get_config('event_match_type', 'startswith') }} {{ get_config('event_match_type', 'startswith') }}
{% if 'mongo' in cfg_minion -%} {% if 'mongo' in cfg_minion -%}
{%- do default_keys.append('mongo') %}
##### mongodb connection settings ##### ##### mongodb connection settings #####
########################################## ##########################################
{%- for name, value in cfg_minion['mongo'].items() %} {%- for name, value in cfg_minion['mongo'].items() %}
@ -1000,8 +1014,17 @@ mongo.{{ name }}: {{ value }}
{%- endfor %} {%- endfor %}
{% if 'alternative.mongo' in cfg_minion -%} {% if 'alternative.mongo' in cfg_minion -%}
{%- do default_keys.append('alternative.mongo') %}
{%- for name, value in cfg_minion['alternative.mongo'].items() %} {%- for name, value in cfg_minion['alternative.mongo'].items() %}
alternative.mongo.{{ name }}: {{ value }} alternative.mongo.{{ name }}: {{ value }}
{%- endfor %} {%- endfor %}
{% endif %} {% endif %}
{%- endif %} {%- endif %}
############ Other settings ############
##########################################
{%- for configname in cfg_minion %}
{%- if configname not in reserved_keys and configname not in default_keys %}
{{ configname }}: {{ cfg_minion[configname]|json }}
{%- endif %}
{%- endfor %}