Skip to content

Commit

Permalink
Merge pull request #410 from cradle8810/rsyslog
Browse files Browse the repository at this point in the history
Rsyslog Initial configuration
  • Loading branch information
cradle8810 authored Jan 8, 2025
2 parents b7039ca + 25966d7 commit a84da3a
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 6 deletions.
40 changes: 40 additions & 0 deletions inventories/host_vars/log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
apt:
- curl
- dstat
- htop
- qemu-guest-agent
- rsyslog

services_start:
- qemu-guest-agent

firewall:
policy: deny
allow_rules:
- name: "SSH from service line"
proto: "tcp"
src: "192.168.1.0/24"
port: '22'
- name: "Rsyslog(UDP) from service line"
proto: "udp"
src: "192.168.1.0/24"
port: '514'
- name: "Rsyslog(TCP) from service line"
proto: "tcp"
src: "192.168.1.0/24"
port: '514'

drives:
hayaworld:
uuid: "eae4947a-1397-48f6-a4c0-c13a3cc30c2a"
mountpoint: "/var/log/hayaworld"
filesystem: "btrfs"
options: "defaults,noatime,compress=zstd:1"

syslog:
logdir: "/var/log/hayaworld"
actions:
- facility: "local5"
priority: "*"
file: "local5.log"
1 change: 1 addition & 0 deletions inventories/host_vars/mai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dnsmasq:
NXDOMAIN_hosts: /etc/dnsmasq.d/NXDOMAIN.conf
logs:
log_facility: local5
log_to: "log.hayaworld.home"

services_start:
- dnsmasq
Expand Down
5 changes: 5 additions & 0 deletions inventories/host_vars/networks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ network:
ipv4: 192.168.1.108
shortname: runner03
sshuser: runner
- hostname: log.hayaworld.home
interface: ens18
ipv4: 192.168.1.109
shortname: log
sshuser: hayato
- hostname: tm.hayaworld.home
interface: ens18
ipv4: 192.168.1.112
Expand Down
1 change: 1 addition & 0 deletions inventories/host_vars/rui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dnsmasq:
NXDOMAIN_hosts: /etc/dnsmasq.d/NXDOMAIN.conf
logs:
log_facility: local5
log_to: "log.hayaworld.home"

services_start:
- dnsmasq
Expand Down
3 changes: 3 additions & 0 deletions inventories/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
[runner03]
192.168.1.108 ansible_user=hayato

[log]
192.168.1.109 ansible_user=hayato

[tm]
192.168.1.112 ansible_user=hayato

Expand Down
26 changes: 26 additions & 0 deletions log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Play for log.hayaworld.home
hosts: log
remote_user: hayato
gather_facts: true
become: true

vars_files:
- inventories/host_vars/log.yml
- inventories/host_vars/networks.yml

handlers:
- name: Restart handler tasks
ansible.builtin.import_tasks:
file: handlers/main.yml

tasks:
- name: Common Settings
ansible.builtin.import_tasks:
file: tasks/all/main.yml

- name: "Install Rsyslog"
ansible.builtin.import_tasks:
file: tasks/log/install_rsyslog.yml
tags:
- rsyslog
41 changes: 41 additions & 0 deletions tasks/log/install_rsyslog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: "Make hayaworld logs mountpoint"
ansible.builtin.file:
path: "{{ drives.hayaworld.mountpoint }}"
state: directory
owner: syslog
group: adm
mode: '0755'

- name: "Mount drive"
ansible.posix.mount:
src: "UUID={{ drives.hayaworld.uuid }}"
path: "{{ drives.hayaworld.mountpoint }}"
fstype: "{{ drives.hayaworld.filesystem }}"
opts: "{{ drives.hayaworld.options }}"
state: mounted

- name: "Install rsyslog"
ansible.builtin.apt:
pkg:
- rsyslog

- name: "Put rsyslog conf"
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: '0644'
notify: "Restart rsyslog"
loop:
- src: templates/log/etc/rsyslog.d/10-hayaworld.conf
dest: /etc/rsyslog.d/10-hayaworld.conf
- src: templates/log/etc/rsyslog.conf
dest: /etc/rsyslog.conf

- name: "Enable rsyslog"
ansible.builtin.systemd_service:
name: systemd-resolved.service
state: started
enabled: true
4 changes: 2 additions & 2 deletions tasks/rui/rsyslog-rui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

- name: Put rsyslog.conf(5)
ansible.builtin.template:
src: templates/rui/etc/rsyslog.conf.rui.j2
dest: /etc/rsyslog.conf
src: templates/rui/etc/rsyslog.d/99-dnsmasq.conf
dest: /etc/rsyslog.d/99-dnsmasq.conf
owner: root
group: root
mode: '0644'
Expand Down
6 changes: 6 additions & 0 deletions templates/log/etc/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_
| | ___ __ _
| |/ _ \ / _` |
| | (_) | (_| |
|_|\___/ \__, |
|___/
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module(load="imuxsock") # provides support for local system logging
#module(load="immark") # provides --MARK-- message capability

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

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

# provides kernel logging support and enable non-kernel klog messages
module(load="imklog" permitnonkernelfacility="on")
Expand Down Expand Up @@ -57,3 +57,6 @@ $WorkDirectory /var/spool/rsyslog
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

$AllowedSender UDP, 127.0.0.1, 192.168.1.0/24, *.hayaworld.home
$AllowedSender TCP, 127.0.0.1, 192.168.1.0/24, *.hayaworld.home
4 changes: 4 additions & 0 deletions templates/log/etc/rsyslog.d/10-hayaworld.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% for list in syslog.actions %}
{{ list.facility }}.{{ list.priority }} {{ syslog.logdir }}/{{ list.file }}
{% endfor %}
& stop
2 changes: 2 additions & 0 deletions templates/mai/etc/rsyslog.d/99-dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ dnsmasq.logs.log_facility }}.* @{{ dnsmasq.logs.log_to }}
& stop
2 changes: 2 additions & 0 deletions templates/rui/etc/rsyslog.d/99-dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ dnsmasq.logs.log_facility }}.* @{{ dnsmasq.logs.log_to }}
& stop

0 comments on commit a84da3a

Please sign in to comment.