Skip to content

Commit 463ad69

Browse files
chenmenaboe76
authored andcommitted
reuse sshd_config from map (#160)
remove duplicated 'pillar.get' calls to retrieve the sshd_config and ssh_config pillars.
1 parent 55b4c68 commit 463ad69

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

openssh/config.sls

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
{% from "openssh/map.jinja" import openssh with context %}
2-
3-
{%- set manage_sshd_config = salt['pillar.get']('sshd_config', False) %}
1+
{% from "openssh/map.jinja" import openssh, ssh_config, sshd_config with context %}
42
53
include:
64
- openssh
75
8-
{% if manage_sshd_config %}
6+
{% if sshd_config %}
97
sshd_config:
108
file.managed:
119
- name: {{ openssh.sshd_config }}
@@ -22,7 +20,7 @@ sshd_config:
2220
- service: {{ openssh.service }}
2321
{% endif %}
2422
25-
{% if salt['pillar.get']('ssh_config', False) %}
23+
{% if ssh_config %}
2624
ssh_config:
2725
file.managed:
2826
- name: {{ openssh.ssh_config }}
@@ -38,15 +36,15 @@ ssh_config:
3836
3937
{%- for keyType in openssh['host_key_algos'].split(',') %}
4038
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
41-
{%- set keySize = salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', False) %}
42-
{%- if salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
39+
{%- set keySize = openssh.get('generate_' ~ keyType ~ '_size', False) %}
40+
{%- if openssh.get('provide_' ~ keyType ~ '_keys', False) %}
4341
ssh_host_{{ keyType }}_key:
4442
file.managed:
4543
- name: {{ keyFile }}
4644
- contents_pillar: 'openssh:{{ keyType }}:private_key'
4745
- user: root
4846
- mode: 600
49-
{%- if manage_sshd_config %}
47+
{%- if sshd_config %}
5048
- require_in:
5149
- file: sshd_config
5250
{%- endif %}
@@ -59,14 +57,14 @@ ssh_host_{{ keyType }}_key.pub:
5957
- contents_pillar: 'openssh:{{ keyType }}:public_key'
6058
- user: root
6159
- mode: 600
62-
{%- if manage_sshd_config %}
60+
{%- if sshd_config %}
6361
- require_in:
6462
- file: sshd_config
6563
{%- endif %}
6664
- watch_in:
6765
- service: {{ openssh.service }}
68-
{%- elif salt['pillar.get']('openssh:generate_' ~ keyType ~ '_keys', False) %}
69-
{%- if keySize and salt['pillar.get']('openssh:enforce_' ~ keyType ~ '_size', False) %}
66+
{%- elif openssh.get('generate_' ~ keyType ~ '_keys', False) %}
67+
{%- if keySize and openssh.get('enforce_' ~ keyType ~ '_size', False) %}
7068
ssh_remove_short_{{ keyType }}_key:
7169
cmd.run:
7270
- name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
@@ -80,7 +78,7 @@ ssh_generate_host_{{ keyType }}_key:
8078
- name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
8179
- unless: "test -s {{ keyFile }}"
8280
- runas: root
83-
{%- if manage_sshd_config %}
81+
{%- if sshd_config %}
8482
- require_in:
8583
- file: sshd_config
8684
{%- endif %}
@@ -94,12 +92,12 @@ ssh_host_{{ keyType }}_key: # set permissions
9492
- mode: 0600
9593
- require:
9694
- cmd: ssh_generate_host_{{ keyType }}_key
97-
{%- if manage_sshd_config %}
95+
{%- if sshd_config %}
9896
- require_in:
9997
- file: sshd_config
10098
{%- endif %}
10199
102-
{%- elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %}
100+
{%- elif openssh.get('absent_' ~ keyType ~ '_keys', False) %}
103101
ssh_host_{{ keyType }}_key:
104102
file.absent:
105103
- name: {{ keyFile }}
@@ -114,7 +112,7 @@ ssh_host_{{ keyType }}_key.pub:
114112
{%- endif %}
115113
{%- endfor %}
116114
117-
{%- if salt['pillar.get']('sshd_config:UsePrivilegeSeparation', '')|lower == 'yes' %}
115+
{%- if sshd_config.get('UsePrivilegeSeparation', '')|lower == 'yes' %}
118116
/var/run/sshd:
119117
file.directory:
120118
- user: root

0 commit comments

Comments
 (0)