openssh-formula/openssh/auth.sls
Daniel Dehennin df477b25c2 feat(map): update to v4 “map.jinja”
The `map.jinja` now exports a single variable called `mapdata`.

We extract the `openssh`, `sshd_config` and `ssh_config` from it to
minimize the changes to `.sls` files.
2020-07-31 10:54:40 +02:00

58 lines
1.6 KiB
Plaintext

{%- 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 'source' in key %}
- source: {{ key['source'] }}
{%- else %}
{%- if 'enc' in key %}
- enc: {{ key['enc'] }}
{%- endif -%}
{%- if 'comment' in key %}
- comment: {{ key['comment'] }}
{%- endif -%}
{%- if 'options' in key %}
- options: {{ key['options'] }}
{%- endif -%}
{%- endif %}
{%- endmacro -%}
include:
- openssh
{%- from "openssh/map.jinja" import mapdata with context -%}
{%- set openssh = mapdata.openssh %}
{%- set sshd_config = mapdata.sshd_config %}
{%- set auth = openssh.get('auth', {}) -%}
{%- for identifier,keys in auth.items() -%}
{%- for key in keys -%}
{% if 'present' in key and key['present'] %}
{{ print_name(identifier, key) }}:
ssh_auth.present:
{{ print_ssh_auth(identifier, key) }}
{%- if sshd_config.get("AuthorizedKeysFile", None) %}
- config: '{{ sshd_config['AuthorizedKeysFile'] }}'
{% endif %}
- require:
- service: {{ openssh.service }}
{%- else %}
{{ print_name(identifier, key) }}:
ssh_auth.absent:
{{ print_ssh_auth(identifier, key) }}
{%- if sshd_config.get("AuthorizedKeysFile", None) %}
- config: '{{ sshd_config['AuthorizedKeysFile'] }}'
{% endif -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}