0
0
mirror of https://github.com/saltstack-formulas/openssh-formula.git synced 2025-08-03 11:13:51 +02:00
openssh-formula/openssh/config_ini.sls
Michael Nunes 888c5f1141
fix(config_ini): added quotes to regex tabs pattern
With Salt-Master 3005.1 and Salt-Minion on 3006.1, both on Debian 11, the unquoted tab was being parsed as part of the yaml structure and throwing the following error:


local:
    Data failed to compile:
----------
    Rendering SLS 'base:openssh.config_ini' failed: Illegal tab character; line 8

---
[...]
include:
  - openssh
sshd_config-with-ini:
  file.replace:
    - name: /etc/ssh/sshd_config
    - pattern: ^(\w+)	+(\w)    <======================
    - repl: '\1 \2'
    - show_changes: True
    - require_in:
      - ini: sshd_config-with-ini

[...]
---
2023-05-22 14:35:12 -03:00

33 lines
969 B
Plaintext

{%- from "openssh/map.jinja" import mapdata with context %}
{%- set openssh = mapdata.openssh %}
{%- set sshd_config = mapdata.sshd_config %}
include:
- openssh
{%- 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: sshd_config-with-ini
{%- endif %}
ini.options_present:
- name: {{ openssh.sshd_config }}
- separator: ' '
- watch_in:
- service: {{ openssh.service }}
- sections:
{%- for k,v in sshd_config.items() %}
{{ k }}: '{{ v }}'
{%- endfor %}
{%- endif %}