From 5abdaee5a2ee333b54e1fa2b26512175e5bcae22 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Mon, 22 Aug 2016 11:22:08 +0100 Subject: [PATCH 1/2] Handle config opts not part of default config. --- salt/files/minion.d/f_defaults.conf | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/salt/files/minion.d/f_defaults.conf b/salt/files/minion.d/f_defaults.conf index 95d5865..172927b 100644 --- a/salt/files/minion.d/f_defaults.conf +++ b/salt/files/minion.d/f_defaults.conf @@ -4,7 +4,9 @@ {% set reserved_keys = ['master', 'minion', 'cloud', 'salt_cloud_certs'] -%} {% set cfg_salt = pillar.get('salt', {}) -%} {% set cfg_minion = cfg_salt.get('minion', {}) -%} +{% set default_keys = [] -%} {%- macro get_config(configname, default_value) -%} +{%- do default_keys.append(configname) %} {%- if configname in cfg_minion -%} {{ configname }}: {{ cfg_minion[configname]|json }} {%- 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 # clusters. {% if 'id' in cfg_minion -%} +{%- do default_keys.append('id') %} id: {{ cfg_minion['id'] }} {% else -%} #id: @@ -205,6 +208,7 @@ id: {{ cfg_minion['id'] }} {{ get_config('ping_interval', '0') }} {%- if 'mine_functions' in cfg_minion %} +{%- do default_keys.append('mine_functions') %} mine_functions: {%- for func, args in cfg_minion['mine_functions'].items() %} {{ func }}: {{ args }} @@ -336,6 +340,7 @@ mine_functions: # # Include a config file from some other path: {% if 'include' in cfg_minion -%} +{%- do default_keys.append('include') %} {% if isinstance(cfg_minion['include'], list) -%} include: {% for include in cfg_minion['include'] -%} @@ -483,6 +488,7 @@ file_client: local # - /srv/salt/prod/services # - /srv/salt/prod/states {% if 'file_roots' in cfg_minion -%} +{%- do default_keys.append('file_roots') %} {{ file_roots(cfg_minion['file_roots']) }} {%- elif 'file_roots' in cfg_salt -%} {{ file_roots(cfg_salt['file_roots']) }} @@ -511,6 +517,7 @@ file_client: local # - git # - roots {% if 'fileserver_backend' in cfg_minion -%} +{%- do default_keys.append('fileserver_backend') %} fileserver_backend: {%- for backend in cfg_minion['fileserver_backend'] %} - {{ backend }} @@ -570,6 +577,7 @@ fileserver_backend: # Note: file:// repos will be treated as a remote, so refs you want used must # exist in that repo as *local* refs. {% if 'gitfs_remotes' in cfg_minion -%} +{%- do default_keys.append('gitfs_remotes') %} gitfs_remotes: {%- for remote in cfg_minion['gitfs_remotes'] %} {%- 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 # control over which branches/tags are exposed as fileserver environments. {% if 'gitfs_env_whitelist' in cfg_minion -%} +{%- do default_keys.append('gitfs_env_whitelist') %} gitfs_env_whitelist: {%- for git_env in cfg_minion['gitfs_env_whitelist'] %} - {{ git_env }} @@ -613,6 +622,7 @@ gitfs_env_whitelist: {% endif %} {% if 'gitfs_env_blacklist' in cfg_minion -%} +{%- do default_keys.append('gitfs_env_blacklist') %} gitfs_env_blacklist: {%- for git_env in cfg_minion['gitfs_env_blacklist'] %} - {{ git_env }} @@ -629,6 +639,7 @@ gitfs_env_blacklist: # this is the case, and pillar data is defined, then the pillar_roots need to # also be configured on the minion: {% if 'pillar_roots' in cfg_minion -%} +{%- do default_keys.append('pillar_roots') %} pillar_roots: {%- for name, roots in cfg_minion['pillar_roots']|dictsort %} {{ name }}: @@ -651,6 +662,7 @@ pillar_roots: {%- endif %} {% if 'ext_pillar' in cfg_minion %} +{%- do default_keys.append('ext_pillar') %} ext_pillar: {%- for pillar in cfg_minion['ext_pillar'] -%} {%- for key in pillar -%} @@ -930,6 +942,7 @@ ext_pillar: {%- if 'module_config' in cfg_minion %} +{%- do default_keys.append('module_config') %} {%- for modkey, modval in cfg_minion.module_config.items() %} {{ modkey }}: {{ modval }} {%- endfor %} @@ -993,6 +1006,7 @@ ext_pillar: {{ get_config('event_match_type', 'startswith') }} {% if 'mongo' in cfg_minion -%} +{%- do default_keys.append('mongo') %} ##### mongodb connection settings ##### ########################################## {%- for name, value in cfg_minion['mongo'].items() %} @@ -1000,8 +1014,17 @@ mongo.{{ name }}: {{ value }} {%- endfor %} {% if 'alternative.mongo' in cfg_minion -%} +{%- do default_keys.append('alternative.mongo') %} {%- for name, value in cfg_minion['alternative.mongo'].items() %} alternative.mongo.{{ name }}: {{ value }} {%- endfor %} {% endif %} -{%- endif %} \ No newline at end of file +{%- 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 %} \ No newline at end of file From 89ece150e61c91e31e1bdb3af9b249fbd5d0fe56 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 23 Aug 2016 09:48:39 +0100 Subject: [PATCH 2/2] Tidy up comments, add some docs/examples. --- README.rst | 2 +- pillar.example | 4 ++++ salt/files/minion.d/f_defaults.conf | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 67e3294..a034960 100644 --- a/README.rst +++ b/README.rst @@ -120,7 +120,7 @@ you control, then you can safely enable the ``Configuration`` ================= -Every option available in the templates can be set in pillar. Settings under 'salt' will be overridden by more specific settings under ``salt['master']``, ``salt['minion']`` or ``salt['cloud']`` +Every option available in the templates can be set in pillar. Settings under 'salt' will be overridden by more specific settings under ``salt['master']``, ``salt['minion']`` or ``salt['cloud']``. Options specified in ``salt['minion']`` which are not present in the default configuration file will be added to the end of the configuration file. :: diff --git a/pillar.example b/pillar.example index 0e7486c..4b0938a 100644 --- a/pillar.example +++ b/pillar.example @@ -132,6 +132,10 @@ salt: mine_functions: network.interface_ip: [eth0] + # other 'non-default' config + auth_keytab: /root/auth.keytab + auth_principal: kadmin/admin + # salt cloud config cloud: master: salt diff --git a/salt/files/minion.d/f_defaults.conf b/salt/files/minion.d/f_defaults.conf index 172927b..4178d42 100644 --- a/salt/files/minion.d/f_defaults.conf +++ b/salt/files/minion.d/f_defaults.conf @@ -1021,8 +1021,6 @@ alternative.mongo.{{ name }}: {{ value }} {% 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 }}