From dbcf22852e6bb379dd0f760547d4e8940c7cb280 Mon Sep 17 00:00:00 2001
From: Freezed <2160318-free_zed@users.noreply.gitlab.com>
Date: Tue, 11 Jan 2022 00:17:34 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20package=20management?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- un/install main, OS related, Desktop env. related
- add repo for signal-desktop
- remove snap packages
- upgrade all
- cache managemet
---
 Makefile                  |  9 +---
 tasks/apt.yml             | 88 +++++++++++++++++++++++++++++++++++++++
 tasks/become_user_cfg.yml |  1 -
 tasks/vars/Debian.yml     |  9 ++++
 tasks/vars/Gnome.yml      |  5 +++
 tasks/vars/Mate.yml       |  5 +++
 tasks/vars/Ubuntu.yml     | 14 +++++++
 tasks/vars/main.yml       | 62 +++++++++++++++++++++++++++
 8 files changed, 185 insertions(+), 8 deletions(-)
 create mode 100644 tasks/apt.yml
 create mode 100644 tasks/vars/Debian.yml
 create mode 100644 tasks/vars/Gnome.yml
 create mode 100644 tasks/vars/Mate.yml
 create mode 100644 tasks/vars/Ubuntu.yml
 create mode 100644 tasks/vars/main.yml

diff --git a/Makefile b/Makefile
index 3f694da..b9bf76f 100644
--- a/Makefile
+++ b/Makefile
@@ -7,16 +7,11 @@ clean:
 
 open_all:
 	${EDITOR} .gitignore inventory Makefile README.md
+	${EDITOR} tasks/files/*
+	${EDITOR} tasks/vars/*
 	${EDITOR} tasks/*.yml
-<<<<<<< HEAD
-=======
 	${EDITOR} tasks/files/sshd_config
-	${EDITOR} tasks/user_cfg/*.yml
-	${EDITOR} tasks/user_cfg/files/dotfiles/*
-	${EDITOR} tasks/user_cfg/templates/*.j2
-	${EDITOR} tasks/user_cfg/vars/*.yml
 	${EDITOR} tasks/vars/*.yml
->>>>>>> eab54ad (fixup! 🚚 Move tasks in dedicated directory)
 
 inventory_generation:
 	cp inventory.sample inventory && ${EDITOR} inventory
diff --git a/tasks/apt.yml b/tasks/apt.yml
new file mode 100644
index 0000000..db31801
--- /dev/null
+++ b/tasks/apt.yml
@@ -0,0 +1,88 @@
+---
+- hosts: "{{ host_list }}"
+  remote_user: root
+
+  tasks:
+
+    - name: INCLUDE_VARS | base
+      ansible.builtin.include_vars: "main.yml"
+
+    - name: INCLUDE_VARS | OS
+      ansible.builtin.include_vars: "{{ ansible_distribution }}.yml"
+
+    - name: INCLUDE_VARS | Gnome
+      when: "'gnome' in group_names"
+      ansible.builtin.include_vars: "Gnome.yml"
+
+    - name: INCLUDE_VARS | Mate
+      when: "'mate' in group_names"
+      ansible.builtin.include_vars: "Mate.yml"
+
+    - name: Remove snap packages
+      when: snap_uninstall_pkg is defined
+      community.general.snap:
+        name: "{{ snap_uninstall_pkg }}"
+        state: absent
+
+    - name: APT | install base & os packages
+      ansible.builtin.apt:
+        cache_valid_time: 3600
+        force_apt_get: yes
+        pkg: "{{ lookup('flattened', base_pkg, os_pkg) }}"
+        state: present
+        update_cache: true
+
+    - name: SIGNAL | add key to keyring
+      when: inventory_hostname in groups.station
+      ansible.builtin.apt_key:
+        url: https://updates.signal.org/desktop/apt/keys.asc
+        keyring: /usr/share/keyrings/signal-desktop-keyring.gpg
+        state: present
+
+    - name: SIGNAL | add apt repository
+      when: inventory_hostname in groups.station
+      ansible.builtin.apt_repository:
+        filename: signal-desktop
+        repo: deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg] https://updates.signal.org/desktop/apt xenial main
+        state: present
+
+    - name: APT | install workstation packages
+      when: inventory_hostname in groups.station
+      ansible.builtin.apt:
+        cache_valid_time: 3600
+        force_apt_get: yes
+        pkg: "{{ lookup('flattened', station_pkg, station_os_pkg, station_wm_pkg) }}"
+        state: present
+        update_cache: true
+
+    - name: APT | uninstall packages
+      ansible.builtin.apt:
+        pkg: "{{ lookup('flattened', base_uninstall_pkg, os_uninstall_pkg) }}"
+        state: absent
+
+    - name: APT | upgrade all packages to the latest version
+      ansible.builtin.apt:
+        force_apt_get: yes
+        upgrade: safe
+
+    - name: APT | remove useless packages from the cache
+      ansible.builtin.apt:
+        force_apt_get: yes
+        autoclean: yes
+        autoremove: yes
+
+    - name: APT | check for restarts
+      ansible.builtin.stat: path={{ item }}
+      register: restart_required
+      loop:
+      - /var/run/firefox-restart-required
+      - /var/run/reboot-required
+      no_log: yes
+
+    - name: APT | restart message
+      ansible.builtin.debug:
+        msg: "{{ item.stat.path | basename }} on {{ ansible_hostname }}"
+      when: item.stat.exists
+      loop: "{{ restart_required.results }}"
+      loop_control:
+        label: "{{ item.item | basename }}"
diff --git a/tasks/become_user_cfg.yml b/tasks/become_user_cfg.yml
index 8fff609..960c5d4 100644
--- a/tasks/become_user_cfg.yml
+++ b/tasks/become_user_cfg.yml
@@ -35,7 +35,6 @@
         state: present
         user: "{{ my_user }}"
 
-
     - name: SSH | Disallow SSH password authentication for root
       become: yes
       copy:
diff --git a/tasks/vars/Debian.yml b/tasks/vars/Debian.yml
new file mode 100644
index 0000000..109b270
--- /dev/null
+++ b/tasks/vars/Debian.yml
@@ -0,0 +1,9 @@
+---
+
+os_pkg: []
+
+os_uninstall_pkg: []
+
+station_os_pkg:
+  - chromium-l10n
+  - firefox-esr-l10n-fr
diff --git a/tasks/vars/Gnome.yml b/tasks/vars/Gnome.yml
new file mode 100644
index 0000000..3717a48
--- /dev/null
+++ b/tasks/vars/Gnome.yml
@@ -0,0 +1,5 @@
+---
+
+station_wm_pkg:
+  - gnome-tweaks
+  - nautilus-nextcloud
diff --git a/tasks/vars/Mate.yml b/tasks/vars/Mate.yml
new file mode 100644
index 0000000..4fb645d
--- /dev/null
+++ b/tasks/vars/Mate.yml
@@ -0,0 +1,5 @@
+---
+
+station_wm_pkg:
+  - mate-tweak
+  - caja-nextcloud
diff --git a/tasks/vars/Ubuntu.yml b/tasks/vars/Ubuntu.yml
new file mode 100644
index 0000000..e2d262c
--- /dev/null
+++ b/tasks/vars/Ubuntu.yml
@@ -0,0 +1,14 @@
+---
+
+os_pkg: []
+
+os_uninstall_pkg:
+  - thunderbird
+
+snap_uninstall_pkg:
+  - firefox
+
+station_os_pkg:
+  - chromium-browser-l10n
+  - firefox-locale-fr
+  - firefox
diff --git a/tasks/vars/main.yml b/tasks/vars/main.yml
new file mode 100644
index 0000000..3911fd6
--- /dev/null
+++ b/tasks/vars/main.yml
@@ -0,0 +1,62 @@
+---
+
+base_pkg:
+  - htop
+  - iotop
+  - locales
+  - lsb-release
+  - lsof
+  - lynx
+  - most
+  - progress
+  - python3-apt
+  - rsync
+  - screen
+  - sudo
+  - tmux
+  - unattended-upgrades
+  - unzip
+  - vim
+  - wget
+  - xkcdpass
+
+base_uninstall_pkg: []
+
+station_pkg:
+  - ansible
+  - cheese
+  - easytag
+  - evolution
+  - evolution-plugins
+  - geany-plugin-addons
+  - geany-plugin-extrasel
+  - geany-plugin-git-changebar
+  - geany-plugin-markdown
+  - geany-plugin-prettyprinter
+  - geany-plugin-shiftcolumn
+  - geany-plugin-spellcheck
+  - geany-plugin-workbench
+  - geany-plugin-xmlsnippets
+  - gimp
+  - git
+  - gnome-disk-utility
+  - gpsprune
+  - hplip
+  - jhead
+  - keepassx
+  - make
+  - meld
+  - mhwaveedit
+  - network-manager-gnome
+  - nextcloud-desktop
+  - pandoc
+  - pdftk
+  - photocollage
+  - sshpass
+  - tree
+  - signal-desktop
+  - simple-scan
+  - soundconverter
+  - system-config-printer
+  - torbrowser-launcher
+  - unrar-free
-- 
GitLab