# syslog-cli.yml
---
- hosts: web
  tasks:
  - name: 1. Installe le paquet rsyslog.
    apt: 
      name: rsyslog
      state: present

  - name: 2. Ajoute la ligne pour forwarder les logs rsyslog au bon endroit.
    lineinfile:
      path: /etc/rsyslog.conf
      line: '*.* @192.168.0.37:514'
      create: yes
    notify: Restart rsyslog

  - name: 3. Forward les logs journald vers syslog.
    replace:
      path: /etc/systemd/journald.conf
      regexp: '^#ForwardToSyslog=yes'
      replace: 'ForwardToSyslog=yes'
    notify: Restart journald

  handlers:
  - name: Restart rsyslog
    service:
      name: rsyslog
      state: restarted

  - name: Restart journald
    service:
      name: systemd-journald
      state: restarted


