I would like to change a line in /etc/default/grub
with puppet to this:
GRUB_CMDLINE_LINUX="cgroup_enable=memory"
I've tried to used augeas which seems to do this magic:
exec { "update_grub":
command => "update-grub",
refreshonly => true,
}
augeas { "grub-serial":
context => "/files/etc/default/grub",
changes => [
"set /files/etc/default/grub/GRUB_CMDLINE_LINUX[last()] cgroup_enable=memory",
],
notify => Exec['update_grub'],
}
It seems to work, but the result string is not in quotes and also I want to make sure that any other values will be separated by space.
GRUB_CMDLINE_LINUX=cgroup_enable=memory
Is there some mechanism how to append values and escape the whole thing?
GRUB_CMDLINE_LINUX="quiet splash cgroup_enable=memory"
For the quoting part, you could use
augeasproviders
'sshellvar
provider and force the quoting style:This will use Augeas internaly (as a Ruby library) on the agent, only in a smarter way.
As for appending to existing values, there's two options:
augeasfacter
to retrieve it), analyze it in your manifest and append to it using theshellvar
type;shellvar
provider so that it appends to the value instead of replacing it.First option
The fact
The following file can be distributed in your module in
${modulepath}/${modulename}/lib/facter/grub_cmdline_linux.rb
and deployed usingpluginsync
.This will return the current value of the fact as a string, and remove the quotes around the value. It requires the Augeas Ruby library on the agent, which I suppose you have if you use the
augeas
type already.Puppet code
The next step is to make use of this value to check if your target value is included. You can split the string and use the
stlib
module functions for this:Run it
Check idempotence:
Second option
If you'd like to have a go at the second option, the best way would probably be to send a (nice) PR to
augeasproviders
'sshellvar
type adding anarray_append
parameter (or a better name):This parameter would treat the value as an array, and append to the existing values if the value is not found already. This would require Ruby coding, but would be reusable in lots of other cases ;-)
Hint: this should happen here.
(for ubuntu users only)
As altering /etc/default/grub is not so nice ..
Just deploy /etc/default/grub.d/memory.cfg
GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX cgroup_enable=memory"
Then update-grub
(see the /etc/default/grub.d/*.cfg feature )