Import the old “create-users” group merge-old-ansible
authornicoo <nicoo@realraum.at>
Thu, 5 Jul 2018 12:11:04 +0000 (14:11 +0200)
committernicoo <nicoo@realraum.at>
Thu, 5 Jul 2018 12:11:04 +0000 (14:11 +0200)
ansible/roles/create-users/defaults/main.yml [new file with mode: 0644]
ansible/roles/create-users/tasks/main.yml [new file with mode: 0644]

diff --git a/ansible/roles/create-users/defaults/main.yml b/ansible/roles/create-users/defaults/main.yml
new file mode 100644 (file)
index 0000000..851480c
--- /dev/null
@@ -0,0 +1 @@
+aux_groups: []
diff --git a/ansible/roles/create-users/tasks/main.yml b/ansible/roles/create-users/tasks/main.yml
new file mode 100644 (file)
index 0000000..598daac
--- /dev/null
@@ -0,0 +1,25 @@
+- name: Install sudo
+  apt:
+    name: sudo
+    state: present
+  when: sudo in aux_groups
+
+- name: Create users
+  become: True
+  user:
+    name:     "{{ item }}"
+    shell:    "{{ users[item].shell }}"
+    groups:   "{{ aux_groups }}"
+  with_items: "{{ user_groups[group] }}"
+
+- name: Set SSH keys for users
+  become: True
+  authorized_key:
+    user: "{{ item }}"
+    key:  "{{ users[item].ssh | join("\n") }}"
+  with_items: "{{ user_groups[group] }}"
+
+# TODO:
+# - on user creation, generate a password and send it, along with useful info
+#   (hostname, IP, SSH host key, ...), by encrypted email;
+# - execute user-specific playbooks for deploying dotfiles?