選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

78 行
2.3 KiB

  1. #!/usr/bin/env ansible-playbook
  2. ---
  3. # Configure Raspberry Pi to log to RAM, with occasional SD card sync
  4. # to reduce SD card writes
  5. # Usage: ansible-playbook -e 'log2ram_size=80M' install_log2ram.yml
  6. - hosts: all
  7. gather_facts: true
  8. gather_subset: min
  9. become: true
  10. vars:
  11. log2ram_repo_url: http://packages.azlux.fr
  12. log2ram_gpg: https://azlux.fr/repo.gpg
  13. log2ram_keyring: /usr/share/keyrings/azlux-archive-keyring.gpg
  14. log2ram_apt_repository: "deb [signed-by={{ log2ram_keyring }}] {{ log2ram_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} main"
  15. log2ram_size: 40M
  16. log2ram_use_rsync: true
  17. log2ram_mail: true
  18. log2ram_path_disk: /var/log
  19. log2ram_use_z2lr: true
  20. log2ram_comp_alg: lz4
  21. log2ram_log_disk_size: 100M
  22. tasks:
  23. - name: Add rsync as pre-requisite
  24. apt:
  25. name: rsync
  26. when: log2ram_use_rsync
  27. - name: Add gpg key
  28. shell:
  29. cmd: >
  30. curl -fsSL {{ log2ram_gpg }} | gpg --dearmor --yes -o {{ log2ram_keyring }}
  31. creates: "{{ log2ram_keyring }}"
  32. - name: Add apt repository
  33. apt_repository:
  34. repo: "{{ log2ram_apt_repository }}"
  35. filename: log2ram
  36. register: log2ram_apt_repo
  37. - name: Update apt cache
  38. apt:
  39. update_cache: true
  40. when: log2ram_apt_repo is changed
  41. - name: Install log2ram
  42. apt:
  43. name: log2ram
  44. notify: Restart log2ram
  45. - name: Set config options
  46. lineinfile:
  47. path: /etc/log2ram.conf
  48. regexp: "{{ item.regexp }}"
  49. line: "{{ item.line }}"
  50. backrefs: true
  51. loop:
  52. - {regexp: '^SIZE=(.*)$', line: 'SIZE={{ log2ram_size }}'}
  53. - {regexp: 'USE_RSYNC=(.*)$', line: 'USE_RSYNC={{ log2ram_use_rsync }}'}
  54. - {regexp: '^MAIL=(.*)$', line: 'MAIL={{ log2ram_mail }}'}
  55. - {regexp: '^PATH_DISK=(.*)$', line: 'PATH_DISK="{{ log2ram_path_disk }}"'}
  56. - {regexp: '^ZL2R=(.*)$', line: 'ZL2R={{ log2ram_use_z2lr|lower }}'}
  57. - {regexp: '^COMP_ALG=(.*)$', line: 'COMP_ALG={{ log2ram_comp_alg }}'}
  58. - {regexp: '^LOG_DISK_SIZE=(.*)$', line: 'LOG_DISK_SIZE={{ log2ram_log_disk_size }}'}
  59. notify: Restart log2ram
  60. handlers:
  61. - name: Restart log2ram
  62. systemd:
  63. name: log2ram
  64. state: restarted