forked from simp/augeasproviders_grub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for global GRUB configuration
This patch adds support for grub_menuentry which provides the ability to manage individual Menu entries for both GRUB Legacy and GRUB2. Testing has been focused on Linux-based operating systems and it is possible that features may be missing for chainloaded operating systems. Support for managing GRUB2 users has also been added. This compares against the *running* configuration, not what is saved in the compilation files in grub.d. The following custom types were created: * grub_config => Manages global GRUB settings * grub_menuentry => Manages GRUB menuentries * grub_user => Manages GRUB2 users Fixes voxpupuli#10
- Loading branch information
1 parent
08b372d
commit 9b969f4
Showing
16 changed files
with
2,669 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# GRUB legacy / 0.9x support for kernel parameters | ||
# | ||
# Copyright (c) 2016 Trevor Vaughan <tvaughan@onyxpoint.com> | ||
# Licensed under the Apache License, Version 2.0 | ||
# Based on work by Dominic Cleal | ||
|
||
Puppet::Type.type(:grub_config).provide(:grub, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do | ||
desc "Uses Augeas API to update kernel parameters in GRUB's menu.lst" | ||
|
||
default_file do | ||
FileTest.exist?("/boot/efi/EFI/redhat/grub.conf") ? "/boot/efi/EFI/redhat/grub.conf" : "/boot/grub/menu.lst" | ||
end | ||
|
||
lens { 'Grub.lns' } | ||
|
||
confine :feature => :augeas | ||
commands :grub => 'grub' | ||
|
||
def self.instances | ||
augopen do |aug| | ||
resources = [] | ||
# Get all global configuration items | ||
# Skip 'title' segments since this provider should not manage them. | ||
params = aug.match("$target/*").delete_if{|pp| pp =~ %r((#comment|/title$)) } | ||
|
||
params.each do |pp| | ||
# Then retrieve all unique values as string (1) or array | ||
val = aug.get(pp) | ||
param = pp.split('/').last | ||
|
||
resource = {:ensure => :present, :name => param} | ||
|
||
if val | ||
val = val[0] if val.size == 1 | ||
resource[:value] = val | ||
end | ||
|
||
resources << new(resource) | ||
end | ||
|
||
resources | ||
end | ||
end | ||
|
||
def exists? | ||
augopen do |aug| | ||
!aug.match("$target/#{resource[:name]}").empty? | ||
end | ||
end | ||
|
||
def create | ||
augopen! do |aug| | ||
aug.insert('$target/title[1]',resource[:name],true) | ||
aug.set("$target/#{resource[:name]}", resource[:value]) | ||
end | ||
end | ||
|
||
def destroy | ||
augopen! do |aug| | ||
aug.rm("$target/#{resource[:name]}") | ||
end | ||
end | ||
|
||
def value | ||
augopen do |aug| | ||
aug.get("$target/#{resource[:name]}") | ||
end | ||
end | ||
|
||
def value=(newval) | ||
augopen! do |aug| | ||
aug.set("$target/#{resource[:name]}", newval) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# GRUB 2 support for kernel parameters, edits /etc/default/grub | ||
# | ||
# Copyright (c) 2016 Trevor Vaughan <tvaughan@onyxpoint.com> | ||
# Licensed under the Apache License, Version 2.0 | ||
# Based on work by Dominic Cleal | ||
|
||
Puppet::Type.type(:grub_config).provide(:grub2, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do | ||
desc "Uses Augeas API to update kernel parameters in GRUB2's /etc/default/grub" | ||
|
||
default_file { '/etc/default/grub' } | ||
|
||
lens { 'Shellvars.lns' } | ||
|
||
def self.mkconfig_path | ||
which("grub2-mkconfig") or which("grub-mkconfig") or '/usr/sbin/grub-mkconfig' | ||
end | ||
|
||
confine :feature => :augeas | ||
commands :mkconfig => mkconfig_path | ||
|
||
defaultfor :osfamily => :RedHat | ||
|
||
def self.instances | ||
augopen do |aug| | ||
resources = [] | ||
|
||
aug.match('$target/*').each do |key| | ||
param = key.split('/').last.strip | ||
val = aug.get(key) | ||
|
||
resource = {:ensure => :present, :name => param} | ||
|
||
if val | ||
val.strip! | ||
resource[:value] = val | ||
end | ||
|
||
resources << new(resource) | ||
end | ||
|
||
resources | ||
end | ||
end | ||
|
||
def exists? | ||
augopen do |aug| | ||
!aug.match("$target/#{resource[:name]}").empty? | ||
end | ||
end | ||
|
||
def create | ||
self.value=(resource[:value]) | ||
end | ||
|
||
def destroy | ||
augopen! do |aug| | ||
aug.rm("$target/#{resource[:name]}") | ||
end | ||
end | ||
|
||
def value | ||
augopen do |aug| | ||
aug.get("$target/#{resource[:name]}") | ||
end | ||
end | ||
|
||
def value=(newval) | ||
augopen! do |aug| | ||
aug.set("$target/#{resource[:name]}", newval) | ||
end | ||
end | ||
|
||
def flush | ||
cfg = nil | ||
["/boot/grub/grub.cfg", "/boot/grub2/grub.cfg"].each {|c| | ||
cfg = c if FileTest.file? c | ||
} | ||
fail("Cannot find grub.cfg location to use with grub-mkconfig") unless cfg | ||
|
||
super | ||
mkconfig "-o", cfg | ||
end | ||
end |
Oops, something went wrong.