reuse sshd_config from map (#160)
remove duplicated 'pillar.get' calls to retrieve the sshd_config and ssh_config pillars.
This commit is contained in:
parent
55b4c68cc8
commit
463ad69d92
@ -1,11 +1,9 @@
|
|||||||
{% from "openssh/map.jinja" import openssh with context %}
|
{% from "openssh/map.jinja" import openssh, ssh_config, sshd_config with context %}
|
||||||
|
|
||||||
{%- set manage_sshd_config = salt['pillar.get']('sshd_config', False) %}
|
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- openssh
|
- openssh
|
||||||
|
|
||||||
{% if manage_sshd_config %}
|
{% if sshd_config %}
|
||||||
sshd_config:
|
sshd_config:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ openssh.sshd_config }}
|
- name: {{ openssh.sshd_config }}
|
||||||
@ -22,7 +20,7 @@ sshd_config:
|
|||||||
- service: {{ openssh.service }}
|
- service: {{ openssh.service }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if salt['pillar.get']('ssh_config', False) %}
|
{% if ssh_config %}
|
||||||
ssh_config:
|
ssh_config:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ openssh.ssh_config }}
|
- name: {{ openssh.ssh_config }}
|
||||||
@ -38,15 +36,15 @@ ssh_config:
|
|||||||
|
|
||||||
{%- for keyType in openssh['host_key_algos'].split(',') %}
|
{%- for keyType in openssh['host_key_algos'].split(',') %}
|
||||||
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
|
{%- set keyFile = "/etc/ssh/ssh_host_" ~ keyType ~ "_key" %}
|
||||||
{%- set keySize = salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', False) %}
|
{%- set keySize = openssh.get('generate_' ~ keyType ~ '_size', False) %}
|
||||||
{%- if salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
|
{%- if openssh.get('provide_' ~ keyType ~ '_keys', False) %}
|
||||||
ssh_host_{{ keyType }}_key:
|
ssh_host_{{ keyType }}_key:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ keyFile }}
|
- name: {{ keyFile }}
|
||||||
- contents_pillar: 'openssh:{{ keyType }}:private_key'
|
- contents_pillar: 'openssh:{{ keyType }}:private_key'
|
||||||
- user: root
|
- user: root
|
||||||
- mode: 600
|
- mode: 600
|
||||||
{%- if manage_sshd_config %}
|
{%- if sshd_config %}
|
||||||
- require_in:
|
- require_in:
|
||||||
- file: sshd_config
|
- file: sshd_config
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
@ -59,14 +57,14 @@ ssh_host_{{ keyType }}_key.pub:
|
|||||||
- contents_pillar: 'openssh:{{ keyType }}:public_key'
|
- contents_pillar: 'openssh:{{ keyType }}:public_key'
|
||||||
- user: root
|
- user: root
|
||||||
- mode: 600
|
- mode: 600
|
||||||
{%- if manage_sshd_config %}
|
{%- if sshd_config %}
|
||||||
- require_in:
|
- require_in:
|
||||||
- file: sshd_config
|
- file: sshd_config
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: {{ openssh.service }}
|
- service: {{ openssh.service }}
|
||||||
{%- elif salt['pillar.get']('openssh:generate_' ~ keyType ~ '_keys', False) %}
|
{%- elif openssh.get('generate_' ~ keyType ~ '_keys', False) %}
|
||||||
{%- if keySize and salt['pillar.get']('openssh:enforce_' ~ keyType ~ '_size', False) %}
|
{%- if keySize and openssh.get('enforce_' ~ keyType ~ '_size', False) %}
|
||||||
ssh_remove_short_{{ keyType }}_key:
|
ssh_remove_short_{{ keyType }}_key:
|
||||||
cmd.run:
|
cmd.run:
|
||||||
- name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
|
- name: "rm -f {{ keyFile }} {{ keyFile }}.pub"
|
||||||
@ -80,7 +78,7 @@ ssh_generate_host_{{ keyType }}_key:
|
|||||||
- name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
|
- name: "rm {{ keyFile }}*; ssh-keygen -t {{ keyType }} {{ keySizePart }} -N '' -f {{ keyFile }}"
|
||||||
- unless: "test -s {{ keyFile }}"
|
- unless: "test -s {{ keyFile }}"
|
||||||
- runas: root
|
- runas: root
|
||||||
{%- if manage_sshd_config %}
|
{%- if sshd_config %}
|
||||||
- require_in:
|
- require_in:
|
||||||
- file: sshd_config
|
- file: sshd_config
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
@ -94,12 +92,12 @@ ssh_host_{{ keyType }}_key: # set permissions
|
|||||||
- mode: 0600
|
- mode: 0600
|
||||||
- require:
|
- require:
|
||||||
- cmd: ssh_generate_host_{{ keyType }}_key
|
- cmd: ssh_generate_host_{{ keyType }}_key
|
||||||
{%- if manage_sshd_config %}
|
{%- if sshd_config %}
|
||||||
- require_in:
|
- require_in:
|
||||||
- file: sshd_config
|
- file: sshd_config
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %}
|
{%- elif openssh.get('absent_' ~ keyType ~ '_keys', False) %}
|
||||||
ssh_host_{{ keyType }}_key:
|
ssh_host_{{ keyType }}_key:
|
||||||
file.absent:
|
file.absent:
|
||||||
- name: {{ keyFile }}
|
- name: {{ keyFile }}
|
||||||
@ -114,7 +112,7 @@ ssh_host_{{ keyType }}_key.pub:
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- if salt['pillar.get']('sshd_config:UsePrivilegeSeparation', '')|lower == 'yes' %}
|
{%- if sshd_config.get('UsePrivilegeSeparation', '')|lower == 'yes' %}
|
||||||
/var/run/sshd:
|
/var/run/sshd:
|
||||||
file.directory:
|
file.directory:
|
||||||
- user: root
|
- user: root
|
||||||
|
Loading…
Reference in New Issue
Block a user