Skip to content

Commit 14966e9

Browse files
myiiaboe76
authored andcommitted
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
1 parent 3e01ad8 commit 14966e9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

openssh/config_ini.sls

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
{% from "openssh/map.jinja" import openssh, sshd_config with context %}
1+
{%- from "openssh/map.jinja" import openssh, sshd_config with context %}
22
33
include:
44
- openssh
55
6-
{% if sshd_config %}
6+
{%- if sshd_config %}
77
sshd_config-with-ini:
8+
{#- Convert any tabs to a single space to prevent false positives #}
9+
{#- Ref: https://github.com/saltstack-formulas/openssh-formula/issues/162 #}
10+
{%- set regex_search_for_tabs = '^(\w+)\t+(\w)' %}
11+
{%- if salt['file.contains_regex'](openssh.sshd_config, regex_search_for_tabs) %}
12+
file.replace:
13+
- name: {{ openssh.sshd_config }}
14+
- pattern: {{ regex_search_for_tabs }}
15+
- repl: '\1 \2'
16+
- show_changes: True
17+
- require_in:
18+
- ini_manage: sshd_config-with-ini
19+
{%- endif %}
20+
821
ini.options_present:
922
- name: {{ openssh.sshd_config }}
1023
- separator: ' '
@@ -14,4 +27,4 @@ sshd_config-with-ini:
1427
{%- for k,v in sshd_config.items() %}
1528
{{ k }}: '{{ v }}'
1629
{%- endfor %}
17-
{% endif %}
30+
{%- endif %}

0 commit comments

Comments
 (0)