From 012e37045823a1ec37e79b440f4b2f0ae5c7b3ec Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@lysator.liu.se>
Date: Wed, 5 Oct 2022 18:23:54 +0200
Subject: [PATCH] Definition for managing Grub 2 config options.

This adds a definition bootloader::grub2::option which can be used
to manage options in /etc/default/grub.  These options are used by
the scripts in /etc/grub.d to control their output when generating
/boot/grub2/grub.cfg.

As these options are so different from the ones Grub 0.x uses, there
is no meaningful way to have a common abstracting definition that just
dispatches to the correct provider; instead this definition, and the
somewhat corresponding bootloader::grub0::option, are intended to be
used directly by users.
---
 manifests/grub2/option.pp | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 manifests/grub2/option.pp

diff --git a/manifests/grub2/option.pp b/manifests/grub2/option.pp
new file mode 100644
index 0000000..b8119e1
--- /dev/null
+++ b/manifests/grub2/option.pp
@@ -0,0 +1,32 @@
+# Copyright © 2022   Thomas Bellman, Linköping, Sweden
+# Licensed under the GNU LGPL v3+; see the README file for more information.
+
+
+/*
+ * Set an option for Grub 2 (in /etc/default/grub).
+ *
+ * Note that these options are quite different from the ones Grub 0.x,
+ * and they actually affect the generation of the /boot/grub2/grub.cfg
+ * file, and only indirectly affects the operation of Grub 2 itself.
+ *
+ * Parameters
+ *  - name	Grub2 option to set or remove
+ *
+ *  - ensure	One of 'present' (the default) or 'absent'.
+ *
+ *  - value	What value to set for the option.  Note that if the value
+ *		needs quoting, e.g. surrounding by double quotes, then
+ *		you need to do so yourself!
+ */
+define bootloader::grub2::option($ensure='present', $value)
+{
+    include bootloader::grub2::rebuild_grub_cfg
+
+    cfgfile::config_option {
+	"bootloader::grub2::option::${name}":
+	    file => '/etc/default/grub',
+	    option => $name, value => $value,
+	    ensure => $ensure,
+	    notify => Class['bootloader::grub2::rebuild_grub_cfg'];
+    }
+}
-- 
GitLab