Chapter 11. Configuring the systemd journal by using the journald RHEL system role

With the journald RHEL system role you can automate the systemd journal, and configure persistent logging by using the Red Hat Ansible Automation Platform.

11.1. Variables of the journald system role

The journald RHEL system role provides a set of variables for customizing the behavior of journald logging service. The role includes the following variables:

journald_persistent
Use this boolean variable to configure journald for storing log files on disk in the /var/log/journal/ directory. When you set this variable to true, logs are stored on disk, otherwise, they are stored in volatile memory. The default value is false.
journald_max_disk_size
Use this variable to specify the maximum size, in megabytes, that journal files can occupy on disk. Refer to the default sizing calculation described in journald.conf(5) manual page.
journald_max_files
Use this variable to specify the maximum number of journal files you want to keep while respecting the journal_max_disk_size setting for journal.
journald_max_file_size
Use this variable to specify the maximum size, in megabytes, of a single journal file.
journald_per_user
Use this boolean variable to configure journald for keeping log data separate for each user. The default value is true and the unprivileged users can read system logs from their own user services. Note that per-user journal files are only available when the journald_persistent variable is set to true.
journald_compression
Use this boolean variable to apply compression to journald data objects that are larger than the default 512 bytes. The default value is true.
journald_sync_interval
Use this variable to specify the time, in minutes, after which journald synchronizes the currently used journal file to disk. By default, the role does not alter the current value.

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.journald/README.md file
  • /usr/share/doc/rhel-system-roles/journald/ directory
  • journald.conf(5) man page

11.2. Configuring persistent logging by using the journald system role

As a system administrator, you can configure persistent logging by using the journald RHEL system role. The following example shows how to set up the journald RHEL system role variables in a playbook to achieve the following goals:

  • Configuring persistent logging
  • Specifying the maximum size of disk space for journal files
  • Configuring journald to keep log data separate for each user
  • Defining the synchronization interval

Prerequisites

Procedure

  1. Create a playbook file, for example ~/playbook.yml, with the following content:

    ---
    - name: Configure persistent logging
      hosts: managed-node-01.example.com
      vars:
        journald_persistent: true
        journald_max_disk_size: 2048
        journald_per_user: true
        journald_sync_interval: 1
      roles:
        - rhel-system-roles.journald

    As a result, the journald service stores your logs persistently on a disk to the maximum size of 2048 MB, and keeps log data separate for each user. The synchronization happens every minute.

  2. Validate the playbook syntax:

    $ ansible-playbook --syntax-check ~/playbook.yml

    Note that this command only validates the syntax and does not protect against a wrong but valid configuration.

  3. Run the playbook:

    $ ansible-playbook ~/playbook.yml

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.journald/README.md file
  • /usr/share/doc/rhel-system-roles/journald/ directory