From bce62aa171f1ccc4ec152d583375bdfa5aa6f6f5 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sun, 6 Apr 2025 16:21:32 +0200 Subject: [PATCH] feat(config): support emptying config The removal option is not suitable for systems where Salt is installed from distribution packages which place back a default configuration. Allow emptying the file instead of removing it, to benefit from removing any undesired, unmanaged, configuration changes in it, whilst not causing ping-pong between Salt and package updates. Signed-off-by: Georg Pfuetzenreuter --- pillar.example | 6 ++++++ salt/defaults.yaml | 2 ++ salt/master.sls | 6 ++++++ salt/minion.sls | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/pillar.example b/pillar.example index dd4088237..aef11ed0c 100644 --- a/pillar.example +++ b/pillar.example @@ -10,9 +10,15 @@ salt: # This state will remove "/etc/salt/minion" when you set this to true. minion_remove_config: true + # /etc/salt/minion will be emptied if you set this to true. + minion_empty_config: true + # This state will remove "/etc/salt/master" when you set this to true. master_remove_config: true + # /etc/salt/master will be emptied if you set this to true. + master_empty_config: true + # Set this to 'py3' to install the Python 3 packages. # The default varies between OS versions. py_ver: 'py3' diff --git a/salt/defaults.yaml b/salt/defaults.yaml index 2b84eec3e..ca607746c 100644 --- a/salt/defaults.yaml +++ b/salt/defaults.yaml @@ -16,7 +16,9 @@ salt: config_path: /etc/salt minion_remove_config: false + minion_empty_config: false master_remove_config: false + master_empty_config: false minion_config_use_TOFS: false master_config_use_TOFS: false diff --git a/salt/master.sls b/salt/master.sls index af9d867d1..c0075f862 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -72,6 +72,12 @@ remove-default-master-conf-file: - name: {{ salt_settings.config_path }}/master - watch_in: - service: salt-master + {% elif salt_settings.master_empty_config %} +empty-default-master-conf-file: + file.managed: + - name: {{ salt_settings.config_path }}/master + - contents: | + # Configuration is managed by Salt {% endif %} # clean up old _defaults.conf file if they have it around diff --git a/salt/minion.sls b/salt/minion.sls index 97db5b321..b944bf8d7 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -181,6 +181,12 @@ salt-minion-beacon-inotify: remove-default-minion-conf-file: file.absent: - name: {{ salt_settings.config_path }}/minion + {% elif salt_settings.minion_empty_config %} +empty-default-minion-conf-file: + file.managed: + - name: {{ salt_settings.config_path }}/master + - contents: | + # Configuration is managed by Salt {% endif %} # clean up old _defaults.conf file if they have it around