|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #!/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: 40M
- log2ram_use_rsync: true
- log2ram_mail: true
- log2ram_path_disk: /var/log
- log2ram_use_z2lr: true
- log2ram_comp_alg: lz4
- log2ram_log_disk_size: 100M
-
-
- tasks:
- - name: Add rsync as pre-requisite
- apt:
- name: rsync
- when: log2ram_use_rsync
-
- - 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: '^MAIL=(.*)$', line: 'MAIL={{ log2ram_mail }}'}
- - {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
|