Newbie question: Update file and then remount /boot


#1

Hello there,
I’m new to chef and trying to write my first “real” recipe.

What I would like to do on my debian machine is:

  1. update grub config file to disable ipv6
  2. remount /boot as rw
  3. execute update-grub
  4. remount /boot as ro

First of all I created this code:
file ‘/etc/grub.d/99_ipv6’ do
content 'GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} ipv6.disable=1"'
mode '0755’
owner 'root’
group 'root’
notifies :run, "execute[mount-boot-rw]"
notifies :run, "execute[update-grub]"
notifies :run, "execute[mount-boot-ro]"
end

Now my 3 execute-ressources:
execute “update-grub” do
command "update-grub"
action :nothing
end

execute "mount-boot-rw" do
    mount '/boot' do
        device '/dev/vda1'
        options 'rw'
        action [:remount]
        only_if { mounted }
    end
end

execute "mount-boot-ro" do
    mount '/boot' do
        device '/dev/vda1'
    options 'remount,nodev,nosuid,noexec,ro'
        action [:remount]
        only_if { mounted }
    end
end

My problem is:
I don’t understand how to modify this code to work.
I could use the mount-ressource directly (without the execute-ressource) but then the mount would be executed without any condition.

Can anyone help me out please?

Thanks in advance.
Karl