From 52218a46cda2ffd9affd9df5bdd7e64c7f798a20 Mon Sep 17 00:00:00 2001
From: Freezed <2160318-free_zed@users.noreply.gitlab.com>
Date: Mon, 14 Mar 2022 00:11:20 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Isolate=20system=20&=20use?=
 =?UTF-8?q?r=20configuration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Some tasks were on both side, this will tidy it.
System and user config are now clearly identified.
---
 tasks/system_cfg/font.yml                   | 17 +++++++
 tasks/system_cfg/main.yml                   | 10 ++---
 tasks/system_cfg/root.yml                   | 49 ---------------------
 tasks/system_cfg/{my_user.yml => shell.yml} |  3 +-
 tasks/user_cfg/my_user.yml                  | 11 ++---
 tasks/user_cfg/root.yml                     | 32 +-------------
 6 files changed, 29 insertions(+), 93 deletions(-)
 create mode 100644 tasks/system_cfg/font.yml
 delete mode 100644 tasks/system_cfg/root.yml
 rename tasks/system_cfg/{my_user.yml => shell.yml} (65%)

diff --git a/tasks/system_cfg/font.yml b/tasks/system_cfg/font.yml
new file mode 100644
index 0000000..6de96ae
--- /dev/null
+++ b/tasks/system_cfg/font.yml
@@ -0,0 +1,17 @@
+---
+
+- name: FONT | JetBrainsMono presence
+  when: inventory_hostname in groups.station
+  ansible.builtin.find:
+    path: "/usr/local/share/fonts/"
+    patterns: "JetBrainsMono*"
+    recurse: yes
+  register: font_presence
+
+- name: FONT | install JetBrainsMono font
+  when: (inventory_hostname in groups.station) and
+        (font_presence.matched < 50)
+  ansible.builtin.unarchive:
+    dest: "/usr/local/share/"
+    remote_src: yes
+    src: https://download.jetbrains.com/fonts/JetBrainsMono-2.242.zip
diff --git a/tasks/system_cfg/main.yml b/tasks/system_cfg/main.yml
index 991e47b..ff73bb2 100644
--- a/tasks/system_cfg/main.yml
+++ b/tasks/system_cfg/main.yml
@@ -6,11 +6,11 @@
 
   tasks:
 
-  - name: "IMPORT_TASKS | root"
-    ansible.builtin.import_tasks: root.yml
+  - name: IMPORT_TASKS | font
+    ansible.builtin.import_tasks: font.yml
 
-  - name: "IMPORT_TASKS | ntp"
+  - name: IMPORT_TASKS | ntp
     ansible.builtin.import_tasks: ntp.yml
 
-  - name: "IMPORT_TASKS | {{ my_user }}"
-    ansible.builtin.import_tasks: my_user.yml
+  - name: IMPORT_TASKS | shell
+    ansible.builtin.import_tasks: shell.yml
diff --git a/tasks/system_cfg/root.yml b/tasks/system_cfg/root.yml
deleted file mode 100644
index 1b1e80e..0000000
--- a/tasks/system_cfg/root.yml
+++ /dev/null
@@ -1,49 +0,0 @@
----
-
-- name: ROOT | dotfiles presence
-  become: no
-  ansible.builtin.copy:
-    src: "{{ item }}"
-    dest: "/root/.{{ item | basename }}"
-    mode: 0640
-    owner: root
-    group: root
-  with_fileglob:
-    ../user_cfg/files/dotfiles/*
-  loop_control:
-    label: "{{ item | basename }}"
-
-- name: ROOT | ZSH files absence
-  become: no
-  ansible.builtin.file:
-    path: "/etc/zsh/zlogin"
-    state: absent
-
-- name: ROOT | Set ZSH for shell
-  become: no
-  ansible.builtin.user:
-    name: root
-    shell: /bin/zsh
-    state: present
-
-- name: ROOT | TEMP-FIX font dir absence
-  become: no
-  ansible.builtin.file:
-    path: "/usr/local/share/fonts/fonts/"
-    state: absent
-
-- name: ROOT | JetBrainsMono presence
-  become: no
-  ansible.builtin.find:
-    path: "/usr/local/share/fonts/"
-    patterns: "JetBrainsMono*"
-    recurse: yes
-  register: font_presence
-
-- name: ROOT | install JetBrainsMono font
-  become: no
-  when: font_presence.matched < 50
-  ansible.builtin.unarchive:
-    dest: "/usr/local/share/"
-    remote_src: yes
-    src: https://download.jetbrains.com/fonts/JetBrainsMono-2.242.zip
diff --git a/tasks/system_cfg/my_user.yml b/tasks/system_cfg/shell.yml
similarity index 65%
rename from tasks/system_cfg/my_user.yml
rename to tasks/system_cfg/shell.yml
index 35b0a13..0f39c03 100644
--- a/tasks/system_cfg/my_user.yml
+++ b/tasks/system_cfg/shell.yml
@@ -1,7 +1,6 @@
 ---
 
-- name: MY USER | set zsh for shell
-  become: no
+- name: "SHELL | set zsh for {{ my_user }}"
   ansible.builtin.user:
     name: "{{ my_user }}"
     shell: /bin/zsh
diff --git a/tasks/user_cfg/my_user.yml b/tasks/user_cfg/my_user.yml
index a1b37a5..d1edc62 100644
--- a/tasks/user_cfg/my_user.yml
+++ b/tasks/user_cfg/my_user.yml
@@ -13,14 +13,8 @@
   loop_control:
     label: "{{ item | basename }}"
 
-- name: MY USER | set zsh for shell
-  become: no
-  ansible.builtin.user:
-    name: "{{ my_user }}"
-    shell: /bin/zsh
-    state: present
-
 - name: MY USER | ssh config
+  become: yes
   ansible.builtin.template:
     src: templates/ssh_config.j2
     dest: "/home/{{ my_user }}/.ssh/config"
@@ -37,6 +31,7 @@
     state: directory
 
 - name: INCLUDE_VARS | git
+  when: inventory_hostname in groups.station
   ansible.builtin.include_vars: "vars/git.yml"
 
 - name: MY USER | clone git repos
@@ -63,6 +58,8 @@
     state: directory
 
 - name: MY USER | gps prune config
+  become: yes
+  when: inventory_hostname in groups.station
   ansible.builtin.template:
     src: templates/pruneconfig.j2
     dest: "/home/{{ my_user }}/.pruneconfig"
diff --git a/tasks/user_cfg/root.yml b/tasks/user_cfg/root.yml
index cd87761..d55dca4 100644
--- a/tasks/user_cfg/root.yml
+++ b/tasks/user_cfg/root.yml
@@ -1,6 +1,6 @@
 ---
 
-- name: ROOT | dotfiles presence
+- name: ROOT | dotfiles
   become: no
   ansible.builtin.copy:
     src: "{{ item }}"
@@ -13,37 +13,9 @@
   loop_control:
     label: "{{ item | basename }}"
 
-- name: ROOT | ZSH files absence
-  become: no
-  ansible.builtin.file:
-    path: "/etc/zsh/zlogin"
-    state: absent
-
-- name: ROOT | Set ZSH for shell
+- name: ROOT | set zsh for shell
   become: no
   ansible.builtin.user:
     name: root
     shell: /bin/zsh
     state: present
-
-- name: ROOT | TEMP-FIX font dir absence
-  become: no
-  ansible.builtin.file:
-    path: "/usr/local/share/fonts/fonts/"
-    state: absent
-
-- name: ROOT | JetBrainsMono presence
-  become: no
-  ansible.builtin.find:
-    path: "/usr/local/share/fonts/"
-    patterns: "JetBrainsMono*"
-    recurse: yes
-  register: font_presence
-
-- name: ROOT | install JetBrainsMono font
-  become: no
-  when: font_presence.matched < 50
-  ansible.builtin.unarchive:
-    dest: "/usr/local/share/"
-    remote_src: yes
-    src: https://download.jetbrains.com/fonts/JetBrainsMono-2.242.zip
-- 
GitLab