Make cgroup enabling idempotent and fix ansible lint checks.

This commit is contained in:
David Putzolu
2020-05-23 09:31:40 -07:00
parent 58d847a78e
commit 9422f65b5b

View File

@@ -1,33 +1,21 @@
---
- name: Check if cgroups enabled
shell: cat /boot/firmware/cmdline.txt | grep cgroup
register: cgroup_enabled
when: ansible_distribution == 'Ubuntu'
# grep will exit with 1 when no results found.
# ignore_errors causes the task not to halt play.
ignore_errors: true
- name: Enable cgroup via boot commandline if not already enabled
lineinfile:
path: /boot/firmware/cmdline.txt
backrefs: yes
regexp: "(.*)$"
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
when:
- ansible_distribution == 'Ubuntu'
- cgroup_enabled.stdout == ""
- name: Check if cgroups already running
shell: cat /proc/cmdline | grep cgroup
register: cgroup_running
- name: Read /proc/cmdline to check for cgroups already running
shell: cat /proc/cmdline
register: cmdline
when:
ansible_distribution == 'Ubuntu'
# grep will exit with 1 when no results found.
# ignore_errors causes the task not to halt play.
ignore_errors: true
- ansible_distribution == 'Ubuntu'
- name: Reboot to enable cgroups if not already running
reboot:
when:
- ansible_distribution == 'Ubuntu'
- cgroup_running.stdout == ""
- '"cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory" not in cmdline.stdout'