From 064d489f41a1cf00f6a38629bb2e21f5241c84b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Jochum?= Date: Mon, 13 Jul 2015 15:59:44 +0200 Subject: [PATCH] Use iteritems() instead of items(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: René Jochum --- openssh/auth.sls | 53 +++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/openssh/auth.sls b/openssh/auth.sls index 33a4f12..a7980c9 100644 --- a/openssh/auth.sls +++ b/openssh/auth.sls @@ -1,15 +1,18 @@ -include: - - openssh -{%- from "openssh/map.jinja" import openssh with context -%} -{%- set openssh_pillar = pillar.get('openssh', {}) -%} -{%- set auth = openssh_pillar.get('auth', {}) -%} -{%- for user,keys in auth.iteritems() -%} - {%- for key in keys -%} - {% if 'present' in key and key['present'] %} -{{ key['name'] }}: - ssh_auth.present: - - user: {{ user }} - {%- if 'source' in key %} +{%- 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 %} - source: {{ key['source'] }} {%- else %} {%- if 'enc' in key %} @@ -22,21 +25,25 @@ include: - options: {{ key['options'] }} {%- endif -%} {%- endif %} +{%- endmacro -%} + +include: + - openssh +{%- from "openssh/map.jinja" import openssh with context -%} +{%- set openssh_pillar = pillar.get('openssh', {}) -%} +{%- set auth = openssh_pillar.get('auth', {}) -%} +{%- for identifier,keys in auth.iteritems() -%} + {%- for key in keys -%} + {% if 'present' in key and key['present'] %} +{{ print_name(identifier, key) }}: + ssh_auth.present: + {{ print_ssh_auth(identifier, key) }} - require: - service: {{ openssh.service }} {%- else %} -{{ key['name'] }}: +{{ print_name(identifier, key) }}: ssh_auth.absent: - - user: {{ user }} - {%- if 'enc' in key %} - - enc: {{ key['enc'] }} - {%- endif -%} - {%- if 'comment' in key %} - - comment: {{ key['comment'] }} - {%- endif -%} - {%- if 'options' in key %} - - options: {{ key['options'] }} - {%- endif -%} + {{ print_ssh_auth(identifier, key) }} {%- endif -%} {%- endfor -%} {%- endfor -%}