--- - name: Stop if no collector was set ansible.builtin.assert: that: - log_forwarding_collector_host | length > 0 fail_msg: "Set log_forwarding_collector_host in group_vars. There is no sensible default for this." - name: Install rsyslog ansible.builtin.package: name: rsyslog state: present # The TLS driver is a separate package on most distributions, and leaving it out # is the most common reason a TLS config silently falls back or fails to start. - name: Install the TLS driver ansible.builtin.package: name: rsyslog-gnutls state: present when: log_forwarding_tls_enabled | bool - name: Check the CA file is actually there ansible.builtin.stat: path: "{{ log_forwarding_tls_ca_file }}" register: log_forwarding_ca when: log_forwarding_tls_enabled | bool - name: Stop if the CA file is missing ansible.builtin.assert: that: - log_forwarding_ca.stat.exists fail_msg: >- {{ log_forwarding_tls_ca_file }} does not exist on {{ inventory_hostname }}. Distribute the CA first, or point log_forwarding_tls_ca_file at the right path. when: log_forwarding_tls_enabled | bool - name: Make sure the queue directory exists ansible.builtin.file: path: "{{ log_forwarding_queue_spool_dir }}" state: directory owner: root group: root mode: "0700" - name: Raise the journald rate limit so it stops dropping before rsyslog sees it ansible.builtin.lineinfile: path: /etc/systemd/journald.conf regexp: '^#?RateLimitBurst=' line: "RateLimitBurst={{ log_forwarding_journald_rate_limit_burst }}" state: present notify: Restart journald - name: Write the forwarding rule ansible.builtin.template: src: forward.conf.j2 dest: /etc/rsyslog.d/10-forward.conf owner: root group: root mode: "0644" validate: rsyslogd -N1 -f %s notify: Restart rsyslog - name: Make sure rsyslog is enabled and running ansible.builtin.service: name: rsyslog enabled: true state: started - name: Flush handlers so the check below runs against the new config ansible.builtin.meta: flush_handlers - name: Send a line the collector can be searched for ansible.builtin.command: >- logger -t iac-verify "log forwarding check from {{ inventory_hostname }}" changed_when: false when: log_forwarding_verify_after_run | bool - name: Confirm rsyslog started without complaining ansible.builtin.command: rsyslogd -N1 changed_when: false register: log_forwarding_config_check failed_when: log_forwarding_config_check.rc != 0 when: log_forwarding_verify_after_run | bool