Ubuntu 14.04.5 and the latest version of
docker-ce in my project. I want to enable the cgroup swap limit capabilities so I'm looking at the section Your kernel does not support cgroup swap limit capabilities.
Instead of doing that manually, I want to modify the
/etc/default/grub file in an Ansible playbook because I already have many playbooks to set up the IT infrastructures.
The simplest solution is to find the
GRUB_CMDLINE_LINUX_DEFAULT line and append
cgroup_enable=memory swapaccount=1 without checking if they already exist. The playbook task would look like this:
- name: Enable the memory limit. lineinfile: path: /etc/default/grub backrefs: yes regexp: '^(GRUB_CMDLINE_LINUX_DEFAULT=")(.*)(".*)$' line: '\1\2 cgroup_enable=memory swapaccount=1\3' when: <String `cgroup_enable=memory swapaccount=1` is not present>
(Note the last
when line is not valid Ansible syntax. I put it there to show the idea.)
I set a
when condition so if these two flags with the desired values are already there, they won't be appended again. However, they are still appended in the cases like the following:
- Only one is present, e.g.:
- Both are present but with different values, e.g.:
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=something swapaccount=999"(just some stupid values)
- Both are present but separated by something else, e.g.:
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory somekey=somevalue swapaccount=1"
In summary, the playbook task is not perfect, and I will improve it soon.
My questions are:
- If I end up with a line like
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=something swapaccount=999 cgroup_enable=memory swapaccount=1", would the values that come later ("memory" and "1" in this case) override the earlier values ("something" and "999") of the same keys?? I tested and it seems to be working this way.
- If it does or does not override the earlier values, where is the official documentation that specifies this behavior? I've tried to find it in the links below but wasn't lucky: