Skip to content

Commit f6dbca3

Browse files
committed
fix: complete PR #164
* Use consistent Jinja whitespace control `{%- ... -}` * Improve debug output (comments & whitespace control) * Use exact state names with TOFS `files_switch` * Add `ssh_known_hosts_src` to `defaults` (for consistency) * Restrict `pillar.example` changes to TOFS only * Use `fire_banner` in `pillar.example` to indicate available template
1 parent a47596f commit f6dbca3

File tree

5 files changed

+35
-42
lines changed

5 files changed

+35
-42
lines changed

openssh/banner.sls

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
{% set tplroot = tpldir.split('/')[0] %}
2-
{% from tplroot ~ "/map.jinja" import openssh with context %}
3-
{% from tplroot ~ "/libtofs.jinja" import files_switch %}
1+
{%- set tplroot = tpldir.split('/')[0] %}
2+
{%- from tplroot ~ "/map.jinja" import openssh with context %}
3+
{%- from tplroot ~ "/libtofs.jinja" import files_switch %}
44
55
include:
66
- openssh
77
88
sshd_banner:
99
file.managed:
1010
- name: {{ openssh.banner }}
11-
{% if openssh.banner_string is defined %}
11+
{%- if openssh.banner_string is defined %}
1212
- contents: {{ openssh.banner_string | yaml }}
13-
{% else %}
14-
# Preserve backward compatibility
15-
- source: {{ openssh.banner_src
16-
if '://' in openssh.banner_src
13+
{%- else %}
14+
{#- Preserve backward compatibility using the `if` below #}
15+
- source: {{ openssh.banner_src if '://' in openssh.banner_src
1716
else files_switch( [openssh.banner_src],
18-
'sshd_banner_file_managed'
17+
'sshd_banner'
1918
) }}
2019
- template: jinja
21-
{% endif %}
20+
{%- endif %}

openssh/config.sls

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
{% set tplroot = tpldir.split('/')[0] %}
2-
{% from tplroot ~ "/map.jinja" import openssh, ssh_config, sshd_config with context %}
3-
{% from tplroot ~ "/libtofs.jinja" import files_switch %}
1+
{%- set tplroot = tpldir.split('/')[0] %}
2+
{%- from tplroot ~ "/map.jinja" import openssh, ssh_config, sshd_config with context %}
3+
{%- from tplroot ~ "/libtofs.jinja" import files_switch %}
44
55
66
include:
77
- openssh
88
9-
{% if sshd_config %}
9+
{%- if sshd_config %}
1010
sshd_config:
1111
file.managed:
1212
- name: {{ openssh.sshd_config }}
13-
# Preserve backward compatibility
14-
- source: {{ openssh.sshd_config_src
15-
if '://' in openssh.sshd_config_src
13+
{#- Preserve backward compatibility using the `if` below #}
14+
- source: {{ openssh.sshd_config_src if '://' in openssh.sshd_config_src
1615
else files_switch( [openssh.sshd_config_src],
17-
'sshd_config_file_managed'
16+
'sshd_config'
1817
) }}
1918
- template: jinja
2019
- user: {{ openssh.sshd_config_user }}
@@ -26,17 +25,16 @@ sshd_config:
2625
{%- endif %}
2726
- watch_in:
2827
- service: {{ openssh.service }}
29-
{% endif %}
28+
{%- endif %}
3029
31-
{% if ssh_config %}
30+
{%- if ssh_config %}
3231
ssh_config:
3332
file.managed:
3433
- name: {{ openssh.ssh_config }}
35-
# Preserve backward compatibility
36-
- source: {{ openssh.ssh_config_src
37-
if '://' in openssh.ssh_config_src
34+
{#- Preserve backward compatibility using the `if` below #}
35+
- source: {{ openssh.ssh_config_src if '://' in openssh.ssh_config_src
3836
else files_switch( [openssh.ssh_config_src],
39-
'ssh_config_file_managed'
37+
'ssh_config'
4038
) }}
4139
- template: jinja
4240
- user: {{ openssh.ssh_config_user }}
@@ -45,7 +43,7 @@ ssh_config:
4543
{%- if openssh.ssh_config_backup %}
4644
- backup: minion
4745
{%- endif %}
48-
{% endif %}
46+
{%- endif %}
4947
5048
{%- for keyType in openssh['host_key_algos'].split(',') %}
5149
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
@@ -134,4 +132,4 @@ ssh_host_{{ keyType }}_key.pub:
134132
- file: sshd_config
135133
- watch_in:
136134
- service: {{ openssh.service }}
137-
{% endif %}
135+
{%- endif %}

openssh/defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ default:
1717
banner: /etc/ssh/banner
1818
banner_src: banner # Default TOFS source filename
1919
ssh_known_hosts: /etc/ssh/ssh_known_hosts
20+
ssh_known_hosts_src: ssh_known_hosts # Default TOFS source filename
2021
dig_pkg: dnsutils
2122
ssh_moduli: /etc/ssh/moduli
2223
root_group: root

openssh/known_hosts.sls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{% set tplroot = tpldir.split('/')[0] %}
2-
{% from tplroot ~ "/map.jinja" import openssh with context %}
3-
{% from tplroot ~ "/libtofs.jinja" import files_switch %}
1+
{%- set tplroot = tpldir.split('/')[0] %}
2+
{%- from tplroot ~ "/map.jinja" import openssh with context %}
3+
{%- from tplroot ~ "/libtofs.jinja" import files_switch %}
44
55
ensure dig is available:
66
pkg.installed:
@@ -10,8 +10,8 @@ ensure dig is available:
1010
manage ssh_known_hosts file:
1111
file.managed:
1212
- name: {{ openssh.ssh_known_hosts }}
13-
- source: {{ files_switch( ['ssh_known_hosts'],
14-
'ssh_known_hosts_file_managed'
13+
- source: {{ files_switch( [openssh.ssh_known_hosts_src],
14+
'manage ssh_known_hosts file'
1515
) }}
1616
- template: jinja
1717
- user: root

pillar.example

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ ssh_config:
194194

195195

196196
openssh:
197-
# Banner file can be retrieved either by TOFS or by url
198-
banner_src: banner_fire
199-
# banner_src: salt://ssh/files/banner_src # <- old style
200-
201197
# Instead of adding a custom banner file you can set it in pillar
202198
banner_string: |
203199
Welcome to {{ grains['id'] }}!
@@ -333,7 +329,6 @@ openssh:
333329
static:
334330
github.com: 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGm[...]'
335331
gitlab.com: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bN[...]'
336-
# The template of ssh_know_host file can be overriden thanks to TOFS
337332

338333
# specify DH parameters (see /etc/ssh/moduli)
339334
moduli: |
@@ -381,11 +376,11 @@ mine_functions:
381376
# files: files_alt
382377
# default: default_alt
383378
source_files:
384-
ssh_known_hosts_file_managed:
385-
- alt_known_hosts
386-
sshd_config_file_managed:
379+
manage ssh_known_hosts file:
380+
- alt_ssh_known_hosts
381+
sshd_config:
387382
- alt_sshd_config
388-
ssh_config_file_managed:
383+
ssh_config:
389384
- alt_ssh_config
390-
sshd_banner_file_managed:
391-
- alt_banner_src
385+
sshd_banner:
386+
- fire_banner

0 commit comments

Comments
 (0)