ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

commit c370ae55f20ceaaad24dc1af7e7fa66d5f127f09
parent fc08da9947be331f1312a9fa44d99463e0afd0eb
Author: Leah Thein <leah@toaster.fritz.box>
Date: Thu, 3 Dec 2020 21:47:40 +0100

common/user: dynamic user creation
3 files changed, 35 insertions(+), 19 deletions(-)
M
playbook-router.yml
|
5
+++++
M
playbook-servers.yml
|
10
++++++++++
M
roles/common/tasks/users.yml
|
39
++++++++++++++++++++-------------------
diff --git a/playbook-router.yml b/playbook-router.yml
@@ -14,6 +14,11 @@
     - frp
   vars:
     alpineVersion: v3.12
+    users:
+      - name: leah
+        groups: "wheel"
+        password: "$6$foobar123$1qcCmnoveirSdWY9XdgH5hCXv32hj0n/AyJX46sSp1LyGCA8QT/xxifebRxr89uIH6vwhzFGgz4.H2sG0en0f0"
+        sshKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw/G6x8H3ojvHx3NsTswBMMmOhp48F3rea0GUniKSvRLMRIti5b7Q4P4FXnkQEtuNSR3u7gE5r4EacaLaIx7Az9SgHRoE+hdzSo4mPAwKTx/E3HZgIjdZhTDL8PAn4SZZT6RBqr/uGb+x9fdIjY0FbdNBLjq0MNnG3T+qd1joUL8JXoS7F//ac52RhHlsA5qJXFDOhpqR/7hRMwOFNH0GKaLN1xQKcOjhpIcdswpOf8kRDVpT7xOYwfXCFF4MaY2M8047WKarvEnGdADIIw6bvWsdJINehtOQmYEFRaMuaWp1d9bglZXZKPQKNubv5lqneMP4AI7ImDYjgW6eNLIT1 cardno:000603502829"
     network:
       hostname: lollo
       domain: ctu.cx
diff --git a/playbook-servers.yml b/playbook-servers.yml
@@ -29,6 +29,11 @@
     - backup 
   vars:
     alpineVersion: edge
+    users:
+      - name: leah
+        groups: "wheel"
+        password: "$6$foobar123$1qcCmnoveirSdWY9XdgH5hCXv32hj0n/AyJX46sSp1LyGCA8QT/xxifebRxr89uIH6vwhzFGgz4.H2sG0en0f0"
+        sshKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw/G6x8H3ojvHx3NsTswBMMmOhp48F3rea0GUniKSvRLMRIti5b7Q4P4FXnkQEtuNSR3u7gE5r4EacaLaIx7Az9SgHRoE+hdzSo4mPAwKTx/E3HZgIjdZhTDL8PAn4SZZT6RBqr/uGb+x9fdIjY0FbdNBLjq0MNnG3T+qd1joUL8JXoS7F//ac52RhHlsA5qJXFDOhpqR/7hRMwOFNH0GKaLN1xQKcOjhpIcdswpOf8kRDVpT7xOYwfXCFF4MaY2M8047WKarvEnGdADIIw6bvWsdJINehtOQmYEFRaMuaWp1d9bglZXZKPQKNubv5lqneMP4AI7ImDYjgW6eNLIT1 cardno:000603502829"
     network:
       hostname: wanderduene
       domain: ctu.cx

@@ -242,6 +247,11 @@
     - rest-server
   vars:
     alpineVersion: edge
+    users:
+      - name: leah
+        groups: "wheel"
+        password: "$6$foobar123$1qcCmnoveirSdWY9XdgH5hCXv32hj0n/AyJX46sSp1LyGCA8QT/xxifebRxr89uIH6vwhzFGgz4.H2sG0en0f0"
+        sshKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw/G6x8H3ojvHx3NsTswBMMmOhp48F3rea0GUniKSvRLMRIti5b7Q4P4FXnkQEtuNSR3u7gE5r4EacaLaIx7Az9SgHRoE+hdzSo4mPAwKTx/E3HZgIjdZhTDL8PAn4SZZT6RBqr/uGb+x9fdIjY0FbdNBLjq0MNnG3T+qd1joUL8JXoS7F//ac52RhHlsA5qJXFDOhpqR/7hRMwOFNH0GKaLN1xQKcOjhpIcdswpOf8kRDVpT7xOYwfXCFF4MaY2M8047WKarvEnGdADIIw6bvWsdJINehtOQmYEFRaMuaWp1d9bglZXZKPQKNubv5lqneMP4AI7ImDYjgW6eNLIT1 cardno:000603502829"
     network:
       hostname: taurus
       domain: ctu.cx
diff --git a/roles/common/tasks/users.yml b/roles/common/tasks/users.yml
@@ -1,33 +1,34 @@
 ---
 
-- name: Add group for leah 
+- name: "Add groups" 
   group:
-    name: leah
+    name: "{{item.name}}"
     state: present
-    gid: 1000
+  loop: "{{ users }}"
 
-
-- name: Add user leah 
+- name: "Add users" 
   user:
     append: yes
-    name: leah
-    uid: 1000
-    group: leah
-    groups: wheel
-    password: $6$foobar123$1qcCmnoveirSdWY9XdgH5hCXv32hj0n/AyJX46sSp1LyGCA8QT/xxifebRxr89uIH6vwhzFGgz4.H2sG0en0f0
+    name: "{{item.name}}"
+    group: "{{item.name}}"
+    groups: "{{item.groups}}"
+    password: "{{item.password}}"
+  loop: "{{ users }}"
 
-- name: create .ssh dir
+- name: "Create ~/.ssh directory for users"
   file:
     state: directory
-    dest: /home/leah/.ssh/
+    dest: "/home/{{item.name}}/.ssh/"
     mode: 0755
-    owner: leah
-    group: leah
+    owner: "{{item.name}}"
+    group: "{{item.name}}"
+  loop: "{{ users }}"
 
-- name: place ssh-key for user
+- name: "Place ssh-key for users"
   copy:
-    content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw/G6x8H3ojvHx3NsTswBMMmOhp48F3rea0GUniKSvRLMRIti5b7Q4P4FXnkQEtuNSR3u7gE5r4EacaLaIx7Az9SgHRoE+hdzSo4mPAwKTx/E3HZgIjdZhTDL8PAn4SZZT6RBqr/uGb+x9fdIjY0FbdNBLjq0MNnG3T+qd1joUL8JXoS7F//ac52RhHlsA5qJXFDOhpqR/7hRMwOFNH0GKaLN1xQKcOjhpIcdswpOf8kRDVpT7xOYwfXCFF4MaY2M8047WKarvEnGdADIIw6bvWsdJINehtOQmYEFRaMuaWp1d9bglZXZKPQKNubv5lqneMP4AI7ImDYjgW6eNLIT1 cardno:000603502829"
-    dest: /home/leah/.ssh/authorized_keys
+    content: "{{item.sshKey}}"
+    dest: "/home/{{item.name}}/.ssh/authorized_keys"
     mode: 0644    
-    owner: leah
-    group: leah
+    owner: "{{item.name}}"
+    group: "{{item.name}}"
+  loop: "{{ users }}"