Browse Source

reuse sshd_config from map (#160)

remove duplicated 'pillar.get' calls to retrieve the sshd_config and ssh_config pillars.
tags/v0.41.0
chenmen 5 years ago
parent
commit
463ad69d92
1 changed files with 13 additions and 15 deletions
  1. +13
    -15
      openssh/config.sls

+ 13
- 15
openssh/config.sls View File

{% from "openssh/map.jinja" import openssh with context %}

{%- set manage_sshd_config = salt['pillar.get']('sshd_config', False) %}
{% from "openssh/map.jinja" import openssh, ssh_config, sshd_config with context %}


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 }}
- 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 }}


{%- 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) %}
{%- if salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
{%- set keySize = openssh.get('generate_' ~ keyType ~ '_size', 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 %}
- 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) %}
{%- if keySize and salt['pillar.get']('openssh:enforce_' ~ keyType ~ '_size', False) %}
{%- elif openssh.get('generate_' ~ keyType ~ '_keys', 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"
- 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 %}
- 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 }}
{%- 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…
Cancel
Save