|
- #!/usr/bin/env ansible-playbook
- ---
- # Configure Raspberry Pi to log to RAM, with occasional SD card sync
- # to reduce SD card writes
- # Usage: ansible-playbook -e 'log2ram_size=80M' install_log2ram.yml
-
- - hosts: all
- gather_facts: true
- gather_subset: min
- become: true
-
-
- vars:
- log2ram_repo_url: http://packages.azlux.fr
- log2ram_gpg: https://azlux.fr/repo.gpg
- log2ram_keyring: /usr/share/keyrings/azlux-archive-keyring.gpg
- log2ram_apt_repository: "deb [signed-by={{ log2ram_keyring }}] {{ log2ram_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} main"
-
- log2ram_size: 128M
- log2ram_use_rsync: true
- log2ram_notification: true
- log2ram_notification_command: 'mail -s "Log2Ram Error on $HOSTNAME"'
- log2ram_path_disk: /var/log
- log2ram_use_z2lr: false
- log2ram_comp_alg: lz4
- log2ram_log_disk_size: 256M
-
-
- tasks:
- - name: Add rsync as pre-requisite
- apt:
- name: rsync
- when: log2ram_use_rsync
-
- - name: Install GnuPG
- apt:
- name: gnupg
-
- - name: Add gpg key
- shell:
- cmd: >
- curl -fsSL {{ log2ram_gpg }} | gpg --dearmor --yes -o {{ log2ram_keyring }}
- creates: "{{ log2ram_keyring }}"
-
- - name: Add apt repository
- apt_repository:
- repo: "{{ log2ram_apt_repository }}"
- filename: log2ram
- register: log2ram_apt_repo
-
- - name: Update apt cache
- apt:
- update_cache: true
- when: log2ram_apt_repo is changed
-
- - name: Install log2ram
- apt:
- name: log2ram
- notify: Restart log2ram
-
- - name: Set config options
- lineinfile:
- path: /etc/log2ram.conf
- regexp: "{{ item.regexp }}"
- line: "{{ item.line }}"
- backrefs: true
- loop:
- - {regexp: '^SIZE=(.*)$', line: 'SIZE={{ log2ram_size }}'}
- - {regexp: 'USE_RSYNC=(.*)$', line: 'USE_RSYNC={{ log2ram_use_rsync }}'}
- - {regexp: '^NOTIFICATION=(.*)$', line: 'NOTIFICATION={{ log2ram_notification }}'}
- - {regexp: '^NOTIFICATION_COMMAND=(.*)$', line: 'NOTIFICATION_COMMAND={{ log2ram_notification_command }}'}
- - {regexp: '^PATH_DISK=(.*)$', line: 'PATH_DISK="{{ log2ram_path_disk }}"'}
- - {regexp: '^ZL2R=(.*)$', line: 'ZL2R={{ log2ram_use_z2lr|lower }}'}
- - {regexp: '^COMP_ALG=(.*)$', line: 'COMP_ALG={{ log2ram_comp_alg }}'}
- - {regexp: '^LOG_DISK_SIZE=(.*)$', line: 'LOG_DISK_SIZE={{ log2ram_log_disk_size }}'}
- notify: Restart log2ram
-
-
- handlers:
- - name: Restart log2ram
- systemd:
- name: log2ram
- state: restarted
|