Skip to content
1 change: 1 addition & 0 deletions roles/_meta/common_base/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
when: is_local is not defined or not is_local
- role: debian/rkhunter
when: is_local is not defined or not is_local
- role: debian/rsyslog
- role: debian/postfix
- role: debian/clamav
when: is_local is not defined or not is_local
Expand Down
74 changes: 49 additions & 25 deletions roles/debian/postfix/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,54 @@
- postfix.disable_syslog is defined
- postfix.disable_syslog

#- name: Restart service.
# ansible.builtin.service:
# name: rsyslog
# state: restarted
- name: Restart rsyslog based on environment to apply postfix changes
block:
- name: Restart rsyslog in a container to apply postfix changes (if is_local is true)
ansible.builtin.shell: |
pkill -HUP rsyslogd || true
when: is_local

- name: Restart rsyslog using systemd to apply postfix changes (if is_local is false)
ansible.builtin.systemd:
name: rsyslog.service
state: restarted
when: is_local is not defined or not is_local

# Needed for Docker.
- name: Stop Postfix
ansible.builtin.command:
cmd: /usr/sbin/service postfix stop

- name: Remove trailing lock files.
ansible.builtin.file:
path: "{{ lock_file }}"
state: absent
with_items:
- /var/spool/postfix/pid/master.pid
- /var/lib/postfix/master.lock
loop_control:
loop_var: lock_file

- name: Create Postfix Aliases database
ansible.builtin.command:
cmd: /usr/bin/newaliases

- name: Restart Postfix
ansible.builtin.command:
cmd: /usr/sbin/service postfix start
- name: Manage Postfix Service
block:
- name: Stop Postfix in a container (if is_local is true)
ansible.builtin.command:
cmd: /usr/sbin/service postfix stop
when: is_local

- name: Stop Postfix using systemd (if is_local is false)
ansible.builtin.systemd:
name: postfix
state: stopped
when: is_local is not defined or not is_local

- name: Remove trailing lock files
ansible.builtin.file:
path: "{{ lock_file }}"
state: absent
with_items:
- /var/spool/postfix/pid/master.pid
- /var/lib/postfix/master.lock
loop_control:
loop_var: lock_file

- name: Create Postfix Aliases database
ansible.builtin.command:
cmd: /usr/bin/newaliases

- name: Start Postfix in a container (if is_local is true)
ansible.builtin.command:
cmd: /usr/sbin/service postfix start
when: is_local

- name: Start Postfix using systemd (if is_local is false)
ansible.builtin.systemd:
name: postfix
state: started
when: is_local is not defined or not is_local
22 changes: 18 additions & 4 deletions roles/debian/rsyslog/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- name: Install rsyslog with apt
ansible.builtin.apt:
name: rsyslog
state: present
update_cache: true

- name: Copy rsyslog configuration in place.
ansible.builtin.template:
src: "rsyslog.{{ rsyslog.role }}.conf.j2"
Expand All @@ -8,7 +14,15 @@
mode: "0644"
force: true

- name: Restart service.
ansible.builtin.service:
name: rsyslog
state: restarted
- name: Restart rsyslog based on environment
block:
- name: Restart rsyslog in a container (if is_local is true)
ansible.builtin.shell: |
pkill -HUP rsyslogd || true
when: is_local

- name: Restart rsyslog using systemd (if is_local is false)
ansible.builtin.systemd:
name: rsyslog.service
state: restarted
when: is_local is not defined or not is_local
90 changes: 19 additions & 71 deletions roles/debian/rsyslog/templates/rsyslog.client.conf.j2
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
# /etc/rsyslog.conf Configuration file for rsyslog.
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
#$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability
module(load="imuxsock") # provides support for local system logging
module(load="imklog") # provides kernel logging support
#module(load="immark") # provides --MARK-- message capability

# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
#module(load="imudp")
#input(type="imudp" port="514")

# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
#module(load="imtcp")
#input(type="imtcp" port="514")


###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

#
# Set the default permissions for all log files.
#
Expand All @@ -54,68 +48,22 @@ $IncludeConfig /etc/rsyslog.d/*.conf
###############
#### RULES ####
###############
*.* @{{ rsyslog.server }}:{{ rsyslog.listen_port }}
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log

#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info -/var/log/mail.info
mail.warn -/var/log/mail.warn
mail.err /var/log/mail.err

#
# Logging for INN news system.
# Log anything besides private authentication messages to a single log file
#
news.crit /var/log/news/news.crit
news.err /var/log/news/news.err
news.notice -/var/log/news/news.notice
*.*;auth,authpriv.none -/var/log/syslog

#
# Some "catch-all" log files.
# Log commonly used facilities to their own log file
#
*.=debug;\
auth,authpriv.none;\
news.none;mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
auth,authpriv.* /var/log/auth.log
cron.* -/var/log/cron.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log

#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*

#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
# news.=crit;news.=err;news.=notice;\
# *.=debug;*.=info;\
# *.=notice;*.=warn /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
# you must invoke `xconsole' with the `-file' option:
#
# $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
*.emerg :omusrmsg:*
Loading