2015-07-13 15:59:44 +02:00
|
|
|
{%- macro print_name(identifier, key) -%}
|
|
|
|
{%- if 'name' in key %}
|
|
|
|
{{ key['name'] }}
|
|
|
|
{%- else %}
|
|
|
|
{{ identifier }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{%- macro print_ssh_auth(identifier, key) -%}
|
|
|
|
{%- if 'user' in key %}
|
|
|
|
- user: {{ key['user'] }}
|
|
|
|
{%- else %}
|
|
|
|
- user: {{ identifier }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'present' in key and key['present'] and 'source' in key %}
|
2014-02-09 23:38:30 +01:00
|
|
|
- source: {{ key['source'] }}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- else %}
|
|
|
|
{%- if 'enc' in key %}
|
2014-02-09 23:38:30 +01:00
|
|
|
- enc: {{ key['enc'] }}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- endif -%}
|
|
|
|
{%- if 'comment' in key %}
|
2014-02-09 23:38:30 +01:00
|
|
|
- comment: {{ key['comment'] }}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- endif -%}
|
|
|
|
{%- if 'options' in key %}
|
2014-02-09 23:38:30 +01:00
|
|
|
- options: {{ key['options'] }}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- endif -%}
|
|
|
|
{%- endif %}
|
2015-07-13 15:59:44 +02:00
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
include:
|
|
|
|
- openssh
|
|
|
|
{%- from "openssh/map.jinja" import openssh with context -%}
|
|
|
|
{%- set openssh_pillar = pillar.get('openssh', {}) -%}
|
|
|
|
{%- set auth = openssh_pillar.get('auth', {}) -%}
|
2015-11-30 13:25:28 +01:00
|
|
|
{%- for identifier,keys in auth.items() -%}
|
2015-07-13 15:59:44 +02:00
|
|
|
{%- for key in keys -%}
|
|
|
|
{% if 'present' in key and key['present'] %}
|
|
|
|
{{ print_name(identifier, key) }}:
|
|
|
|
ssh_auth.present:
|
|
|
|
{{ print_ssh_auth(identifier, key) }}
|
2015-11-18 20:33:50 +01:00
|
|
|
{%- if 'sshd_config' in pillar and 'AuthorizedKeysFile' in pillar['sshd_config'] %}
|
2016-08-02 09:54:46 +02:00
|
|
|
- config: '{{ pillar['sshd_config']['AuthorizedKeysFile'] }}'
|
2016-11-02 15:21:50 +01:00
|
|
|
{% endif %}
|
2014-02-09 23:38:30 +01:00
|
|
|
- require:
|
|
|
|
- service: {{ openssh.service }}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- else %}
|
2015-07-13 15:59:44 +02:00
|
|
|
{{ print_name(identifier, key) }}:
|
2014-02-09 23:38:30 +01:00
|
|
|
ssh_auth.absent:
|
2015-07-13 15:59:44 +02:00
|
|
|
{{ print_ssh_auth(identifier, key) }}
|
2015-11-18 20:33:50 +01:00
|
|
|
{%- if 'sshd_config' in pillar and 'AuthorizedKeysFile' in pillar['sshd_config'] %}
|
2016-08-02 09:54:46 +02:00
|
|
|
- config: '{{ pillar['sshd_config']['AuthorizedKeysFile'] }}'
|
2015-11-18 20:33:50 +01:00
|
|
|
{% endif -%}
|
2014-04-24 00:29:47 +02:00
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
2016-11-02 15:21:50 +01:00
|
|
|
{%- endfor -%}
|