Skip to content

Commit

Permalink
More flexible cgroup settings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
anon-software committed Aug 6, 2024
1 parent b6e4c8b commit 5c8cb11
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
13 changes: 9 additions & 4 deletions roles/raspberrypi/tasks/prereq/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions roles/raspberrypi/tasks/prereq/CentOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
- name: Enable cgroup via boot commandline if not already enabled

Check failure on line 2 in roles/raspberrypi/tasks/prereq/CentOS.yml

View workflow job for this annotation

GitHub Actions / Lint

args[module]

Unsupported parameters for (basic.py) module: replace. Supported parameters include: attributes, backrefs, backup, create, firstmatch, group, insertafter, insertbefore, line, mode, owner, path, regexp, search_string, selevel, serole, setype, seuser, state, unsafe_writes, validate (attr, dest, destfile, name, regex, value).
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
13 changes: 9 additions & 4 deletions roles/raspberrypi/tasks/prereq/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions roles/raspberrypi/tasks/prereq/Raspbian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
- name: Enable cgroup via boot commandline if not already enabled

Check failure on line 2 in roles/raspberrypi/tasks/prereq/Raspbian.yml

View workflow job for this annotation

GitHub Actions / Lint

args[module]

Unsupported parameters for (basic.py) module: replace. Supported parameters include: attributes, backrefs, backup, create, firstmatch, group, insertafter, insertbefore, line, mode, owner, path, regexp, search_string, selevel, serole, setype, seuser, state, unsafe_writes, validate (attr, dest, destfile, name, regex, value).
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
Expand Down
11 changes: 8 additions & 3 deletions roles/raspberrypi/tasks/prereq/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c8cb11

Please sign in to comment.