From 843c44389954358962b4533ea6a9336713ac9826 Mon Sep 17 00:00:00 2001 From: Wolfgang Medina-Erhardt Date: Thu, 7 Nov 2024 15:36:19 +0100 Subject: [PATCH 1/2] Enable precise timestamps for rsyslog on Linux --- defaults/main.yaml | 3 +++ tasks/main.yaml | 3 +++ tasks/rsyslog.yaml | 9 +++++++++ 3 files changed, 15 insertions(+) create mode 100644 tasks/rsyslog.yaml diff --git a/defaults/main.yaml b/defaults/main.yaml index 9714f89..136d643 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -9,7 +9,10 @@ system: config: PasswordAuthentication: no PermitRootLogin: no + rsyslog: + precise_timestamps: no features: + rsyslog: "{{ ansible_system == 'Linux' }}" sshd: yes proserver_fact: no hostname: yes diff --git a/tasks/main.yaml b/tasks/main.yaml index a87b6c9..ce289ac 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -7,6 +7,9 @@ - ansible.builtin.include_tasks: proserver_fact.yaml when: system.features.proserver_fact +- ansible.builtin.include_tasks: rsyslog.yaml + when: system.features.rsyslog + - ansible.builtin.include_tasks: hostname.yaml when: system.features.hostname diff --git a/tasks/rsyslog.yaml b/tasks/rsyslog.yaml new file mode 100644 index 0000000..2327210 --- /dev/null +++ b/tasks/rsyslog.yaml @@ -0,0 +1,9 @@ +--- +- name: Ensure precise timestamps are enabled for rsyslog + when: system.rsyslog.precise_timestamps + ansible.builtin.lineinfile: + path: /etc/rsyslog.conf + regexp: '^\$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat$' + line: '#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat' + owner: root + mode: "0644" From f10149957e29c029c7a2903d1aed7d06b00cae5b Mon Sep 17 00:00:00 2001 From: Wolfgang Medina-Erhardt Date: Thu, 7 Nov 2024 15:46:29 +0100 Subject: [PATCH 2/2] Add a restart rsyslogd handler --- handlers/main.yaml | 5 +++++ tasks/rsyslog.yaml | 1 + 2 files changed, 6 insertions(+) diff --git a/handlers/main.yaml b/handlers/main.yaml index add365a..dea76a0 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -13,3 +13,8 @@ - name: Reload systemd units ansible.builtin.systemd: daemon_reload: yes + +- name: Restart rsyslog + ansible.builtin.systemd: + name: rsyslog + state: restarted diff --git a/tasks/rsyslog.yaml b/tasks/rsyslog.yaml index 2327210..83b6832 100644 --- a/tasks/rsyslog.yaml +++ b/tasks/rsyslog.yaml @@ -1,5 +1,6 @@ --- - name: Ensure precise timestamps are enabled for rsyslog + notify: Restart rsyslog when: system.rsyslog.precise_timestamps ansible.builtin.lineinfile: path: /etc/rsyslog.conf