ansible/roles/base: Light refactoring
authornicoo <nicoo@realraum.at>
Wed, 15 Nov 2017 00:43:33 +0000 (01:43 +0100)
committernicoo <nicoo@realraum.at>
Wed, 15 Nov 2017 00:43:33 +0000 (01:43 +0100)
ansible/roles/base/tasks/main.yaml

index 1e53273..c62d223 100644 (file)
@@ -1,4 +1,9 @@
 ---
+- set_fact:
+    sshd_allowusers: >-
+      {{ [ 'root' ] | union(sshd_allowusers_group | default([]))
+                    | union(sshd_allowusers_host  | default([])) }}
+
 - name: only allow pubkey auth for root
   lineinfile:
      dest: /etc/ssh/sshd_config
@@ -10,7 +15,7 @@
   lineinfile:
      dest: /etc/ssh/sshd_config
      regexp: "^#?AllowUsers"
-     line: "AllowUsers {{ ' '.join([ 'root' ] | union(sshd_allowusers_group | default([])) | union(sshd_allowusers_host | default([]))) }}"
+     line: "AllowUsers {{ ' '.join(sshd_allowusers) }}"
   when: sshd_allowusers_set is defined and sshd_allowgroup is not defined
   notify: restart ssh
 
@@ -32,7 +37,7 @@
         name: "{{ item }}"
         groups: "{{ sshd_allowgroup }}"
         append: True
-      with_items: "{{ [ 'root' ] | union(sshd_allowusers_group | default([])) | union(sshd_allowusers_host | default([])) }}"
+      with_items: "{{ sshd_allowusers }}"
 
   when: sshd_allowgroup is defined