From 14966e9a0964cbec7a1a2574839c0c2ddad5ba77 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sun, 23 Jun 2019 13:33:54 +0100 Subject: [PATCH] fix(`config_ini`): convert tabs to single space to prevent false +ves (#163) * Fix #162 * Check for any number of tabs after the keyword * If found, replace them by a single space to match the `separator` used in the `ini_options.present` state --- openssh/config_ini.sls | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/openssh/config_ini.sls b/openssh/config_ini.sls index f418522..3603eb1 100644 --- a/openssh/config_ini.sls +++ b/openssh/config_ini.sls @@ -1,10 +1,23 @@ -{% from "openssh/map.jinja" import openssh, sshd_config with context %} +{%- from "openssh/map.jinja" import openssh, sshd_config with context %} include: - openssh -{% if sshd_config %} +{%- if sshd_config %} sshd_config-with-ini: + {#- Convert any tabs to a single space to prevent false positives #} + {#- Ref: https://github.com/saltstack-formulas/openssh-formula/issues/162 #} + {%- set regex_search_for_tabs = '^(\w+)\t+(\w)' %} + {%- if salt['file.contains_regex'](openssh.sshd_config, regex_search_for_tabs) %} + file.replace: + - name: {{ openssh.sshd_config }} + - pattern: {{ regex_search_for_tabs }} + - repl: '\1 \2' + - show_changes: True + - require_in: + - ini_manage: sshd_config-with-ini + {%- endif %} + ini.options_present: - name: {{ openssh.sshd_config }} - separator: ' ' @@ -14,4 +27,4 @@ sshd_config-with-ini: {%- for k,v in sshd_config.items() %} {{ k }}: '{{ v }}' {%- endfor %} -{% endif %} +{%- endif %}