From 5c8cb119b657d2256947e20e87bf03f2698d63d4 Mon Sep 17 00:00:00 2001 From: Marko Vukovic Date: Mon, 5 Aug 2024 22:11:20 -0700 Subject: [PATCH] More flexible cgroup settings If there are already required cgroup boot parameters present but in a different order than specified, the script will add them again. It is better to test for the individual parameter in a loop and selectively add them as necessary. Signed-off-by: Marko Vukovic --- roles/raspberrypi/tasks/prereq/Archlinux.yml | 13 +++++++++---- roles/raspberrypi/tasks/prereq/CentOS.yml | 11 ++++++++--- roles/raspberrypi/tasks/prereq/Debian.yml | 13 +++++++++---- roles/raspberrypi/tasks/prereq/Raspbian.yml | 11 ++++++++--- roles/raspberrypi/tasks/prereq/Ubuntu.yml | 11 ++++++++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/roles/raspberrypi/tasks/prereq/Archlinux.yml b/roles/raspberrypi/tasks/prereq/Archlinux.yml index c70756869..fe6dc6d98 100644 --- a/roles/raspberrypi/tasks/prereq/Archlinux.yml +++ b/roles/raspberrypi/tasks/prereq/Archlinux.yml @@ -1,8 +1,13 @@ --- - name: Enable cgroup via boot commandline if not already enabled - ansible.builtin.lineinfile: + ansible.builtin.replace: path: /boot/boot.txt - regexp: '^(setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr="\${usbethaddr}")' - line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' - backrefs: true + regexp: '^(setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr="\${usbethaddr}"(?!.*\b{{ cgroup_item }}\b).*)$' + replace: '\1 {{ cgroup_item }}' + with_items: + - "cgroup_enable=cpuset" + - "cgroup_memory=1" + - "cgroup_enable=memory" + loop_control: + loop_var: cgroup_item notify: Regenerate bootloader image diff --git a/roles/raspberrypi/tasks/prereq/CentOS.yml b/roles/raspberrypi/tasks/prereq/CentOS.yml index 30043d2db..039032e0d 100644 --- a/roles/raspberrypi/tasks/prereq/CentOS.yml +++ b/roles/raspberrypi/tasks/prereq/CentOS.yml @@ -2,7 +2,12 @@ - name: Enable cgroup via boot commandline if not already enabled ansible.builtin.lineinfile: path: /boot/cmdline.txt - backrefs: true - regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' - line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$' + replace: '\1 {{ cgroup_item }}' + with_items: + - "cgroup_enable=cpuset" + - "cgroup_memory=1" + - "cgroup_enable=memory" + loop_control: + loop_var: cgroup_item notify: Reboot Pi diff --git a/roles/raspberrypi/tasks/prereq/Debian.yml b/roles/raspberrypi/tasks/prereq/Debian.yml index aa003e3eb..8dc260da5 100644 --- a/roles/raspberrypi/tasks/prereq/Debian.yml +++ b/roles/raspberrypi/tasks/prereq/Debian.yml @@ -5,11 +5,16 @@ register: boot_firmware_cmdline_txt - name: Enable cgroup via boot commandline if not already enabled - ansible.builtin.lineinfile: + ansible.builtin.replace: path: "{{ (boot_firmware_cmdline_txt.stat.exists) | ternary('/boot/firmware/cmdline.txt', '/boot/cmdline.txt') }}" - backrefs: true - regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' - line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$' + replace: '\1 {{ cgroup_item }}' + with_items: + - "cgroup_enable=cpuset" + - "cgroup_memory=1" + - "cgroup_enable=memory" + loop_control: + loop_var: cgroup_item notify: Reboot Pi - name: Gather the package facts diff --git a/roles/raspberrypi/tasks/prereq/Raspbian.yml b/roles/raspberrypi/tasks/prereq/Raspbian.yml index 1ce8d5bf7..6e63d0667 100644 --- a/roles/raspberrypi/tasks/prereq/Raspbian.yml +++ b/roles/raspberrypi/tasks/prereq/Raspbian.yml @@ -2,9 +2,14 @@ - name: Enable cgroup via boot commandline if not already enabled ansible.builtin.lineinfile: path: /boot/cmdline.txt - backrefs: true - regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' - line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$' + replace: '\1 {{ cgroup_item }}' + with_items: + - "cgroup_enable=cpuset" + - "cgroup_memory=1" + - "cgroup_enable=memory" + loop_control: + loop_var: cgroup_item notify: Reboot Pi - name: Gather the package facts diff --git a/roles/raspberrypi/tasks/prereq/Ubuntu.yml b/roles/raspberrypi/tasks/prereq/Ubuntu.yml index 71cc24b58..e9191fdf7 100644 --- a/roles/raspberrypi/tasks/prereq/Ubuntu.yml +++ b/roles/raspberrypi/tasks/prereq/Ubuntu.yml @@ -3,9 +3,14 @@ when: lookup('fileglob', '/boot/firmware/cmdline.txt', errors='warn') | length > 0 ansible.builtin.lineinfile: path: /boot/firmware/cmdline.txt - backrefs: true - regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' - line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$' + replace: '\1 {{ cgroup_item }}' + with_items: + - "cgroup_enable=cpuset" + - "cgroup_memory=1" + - "cgroup_enable=memory" + loop_control: + loop_var: cgroup_item notify: Reboot Pi - name: Install Ubuntu Raspi Extra Packages