From 2c68783db04a8d4d2575f07ffc44cf62994a9532 Mon Sep 17 00:00:00 2001
From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de>
Date: Sat, 10 Jun 2023 14:19:29 +0200
Subject: [PATCH] basic-system: RHEL support

---
 basic-system/handlers/main.yml           |  8 +++++
 basic-system/tasks/debian.yml            | 30 +++++++++++++++++
 basic-system/tasks/logging.yml           |  9 +++--
 basic-system/tasks/main.yml              | 42 ++++++++----------------
 basic-system/tasks/network.yml           |  4 +--
 basic-system/tasks/redhat.yml            | 15 +++++++++
 basic-system/templates/hosts.j2          |  5 +++
 basic-system/templates/logrotate.conf.j2 |  2 +-
 8 files changed, 80 insertions(+), 35 deletions(-)
 create mode 100644 basic-system/tasks/debian.yml
 create mode 100644 basic-system/tasks/redhat.yml

diff --git a/basic-system/handlers/main.yml b/basic-system/handlers/main.yml
index 4213194..aceb907 100644
--- a/basic-system/handlers/main.yml
+++ b/basic-system/handlers/main.yml
@@ -25,3 +25,11 @@
   shell:  # noqa 303
     chdir: /etc
     cmd: git rm --cached -r -- pve && git commit -m "'Remove pve directory'"
+
+- name: etckeeper initial commit
+  command: etckeeper commit "Initial import"
+
+- name: flush journal
+  systemd:
+    name: systemd-journal-flush.service
+    state: restarted
diff --git a/basic-system/tasks/debian.yml b/basic-system/tasks/debian.yml
new file mode 100644
index 0000000..27cd0ec
--- /dev/null
+++ b/basic-system/tasks/debian.yml
@@ -0,0 +1,30 @@
+---
+
+- name: ensure lsb release information is available
+  apt:
+    name: lsb-release
+    state: present
+  notify:
+    - gather minimal standard facts once again
+  tags:
+    - lsb
+
+- meta: flush_handlers
+
+- name: Check for Proxmox
+  stat:
+    path: /etc/pve
+  register: pve_present
+  tags:
+    - etckeeper
+
+- name: Ignore Proxmox config in etckeeper
+  lineinfile:
+    path: /etc/.gitignore
+    line: /pve
+    create: true
+  when: etckeeper and pve_present.stat.exists
+  notify:
+    - Remove pve directory from etckeeper repo
+  tags:
+    - etckeeper
diff --git a/basic-system/tasks/logging.yml b/basic-system/tasks/logging.yml
index f375326..c46a715 100644
--- a/basic-system/tasks/logging.yml
+++ b/basic-system/tasks/logging.yml
@@ -19,6 +19,7 @@
   when:
     - ansible_distribution_major_version|int(default=99) < 11
     - journal_persistent_with_package
+    - is_debian
   tags:
     - syslog
     - journal
@@ -27,11 +28,12 @@
   file:
     path: /var/log/journal
     state: directory
-  when:
-    - ansible_distribution_major_version|int(default=99) < 11
-    - not journal_persistent_with_package
+  when: >-
+    not is_debian or (ansible_distribution_major_version|int(default=99) < 11
+    and not journal_persistent_with_package)
   notify:
     - configure journal directory
+    - flush journal
   tags:
     - syslog
     - journal
@@ -44,6 +46,7 @@
     dpkg_options: "force-confdef,force-confold,force-depends"
   when:
     - syslogserver is not defined or syslogserver.split(":")[0] != ansible_fqdn
+    - is_debian
   tags:
     - syslog
 
diff --git a/basic-system/tasks/main.yml b/basic-system/tasks/main.yml
index 0781cb0..922ad82 100644
--- a/basic-system/tasks/main.yml
+++ b/basic-system/tasks/main.yml
@@ -10,44 +10,28 @@
   tags:
     - mount
 
-- name: ensure lsb release information is available
-  apt:
-    name: lsb-release
-    state: present
-  notify:
-    - gather minimal standard facts once again
-  tags:
-    - lsb
-- meta: flush_handlers
-
-- name: Check for Proxmox
-  stat:
-    path: /etc/pve
-  register: pve_present
-  tags:
-    - etckeeper
-
-- name: Ignore Proxmox config in etckeeper
-  lineinfile:
-    path: /etc/.gitignore
-    line: /pve
-    create: true
-  when: etckeeper and pve_present.stat.exists
-  notify:
-    - Remove pve directory from etckeeper repo
-  tags:
-    - etckeeper
+- include_tasks: "{{ ansible_distribution_file_variety|lower }}.yml"
 
 - name: Install etckeeper
-  apt:
+  package:
     name: etckeeper
     state: present
   when: etckeeper
   tags:
     - etckeeper
 
+- name: Initialise etckeeper
+  command:
+    cmd: etckeeper init
+    creates: /etc/.git
+  when: etckeeper
+  notify:
+    - etckeeper initial commit
+  tags:
+    - etckeeper
+
 - name: Uninstall etckeeper
-  apt:
+  package:
     name: etckeeper
     state: absent
   when: not etckeeper
diff --git a/basic-system/tasks/network.yml b/basic-system/tasks/network.yml
index 35b4795..bd2e87d 100644
--- a/basic-system/tasks/network.yml
+++ b/basic-system/tasks/network.yml
@@ -11,7 +11,7 @@
     - dns
 
 - name: ensure dbus is installed, since hostnamectl needs this
-  apt:
+  package:
     name: dbus
     state: present
   tags:
@@ -93,7 +93,7 @@
     - sysctl
 
 - name: ensure openssl is installed
-  apt:
+  package:
     name:
       - openssl
       - ca-certificates
diff --git a/basic-system/tasks/redhat.yml b/basic-system/tasks/redhat.yml
new file mode 100644
index 0000000..c36364b
--- /dev/null
+++ b/basic-system/tasks/redhat.yml
@@ -0,0 +1,15 @@
+---
+
+### currently broken
+### https://bugzilla.redhat.com/show_bug.cgi?id=2088871
+
+# - name: ensure lsb release information is available
+#   dnf:
+#     name: redhat-lsb-core
+#     state: present
+#   notify:
+#     - gather minimal standard facts once again
+#   tags:
+#     - lsb
+
+# - meta: flush_handlers
diff --git a/basic-system/templates/hosts.j2 b/basic-system/templates/hosts.j2
index e26791f..414ad19 100644
--- a/basic-system/templates/hosts.j2
+++ b/basic-system/templates/hosts.j2
@@ -1,5 +1,10 @@
+{% if is_debian %}
 127.0.0.1	localhost
 ::1     localhost ip6-localhost ip6-loopback
+{% elif is_rhel %}
+127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
+::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
+{% endif %}
 fe00::0 ip6-localnet
 ff00::0 ip6-mcastprefix
 ff02::1 ip6-allnodes
diff --git a/basic-system/templates/logrotate.conf.j2 b/basic-system/templates/logrotate.conf.j2
index b25502e..f14bf68 100644
--- a/basic-system/templates/logrotate.conf.j2
+++ b/basic-system/templates/logrotate.conf.j2
@@ -21,7 +21,7 @@ delaycompress
 # packages drop log rotation information into this directory
 include /etc/logrotate.d
 
-{% if ansible_distribution_major_version|int(default=99) < 10 %}
+{% if is_debian and ansible_distribution_major_version|int(default=99) < 10 %}
 # no packages own wtmp, or btmp -- we'll rotate them here
 /var/log/wtmp {
     missingok
-- 
GitLab