Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erobhal committed Feb 3, 2016
0 parents commit 02af515
Show file tree
Hide file tree
Showing 16 changed files with 506 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.swo
*.swp
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rvm: 1.9.3
notifications:
email:
- [email protected]
env:
- PUPPET_VERSION=2.6.14
- PUPPET_VERSION=2.7.11
- PUPPET_VERSION=3.3.1
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source 'https://rubygems.org'

group :development, :test do
gem 'json', :require => false
gem 'metadata-json-lint', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[![Build Status](https://travis-ci.org/erobhal/puppet-module-grub2.svg?branch=master)](https://travis-ci.org/erobhal/puppet-module-grub2)

# erobhal-grub2

This module manages GRUB 2 bootloader. It does not modify the
grub2 configurations files directly but changes the OS specific
configuration files (for example /etc/sysconfig/grub on RedHat)
and then uses the OS supplied grub2-mkconfig to generate
the config files. It will never reboot a system after
configuration.

## Supported distributions
- Red Hat

## Parameters

#### config_template
- Internal. Puppet template to use
- **STRING** : *'grub2/grub.erb'*

#### all_cmdline_linux_extra
- Internal. Used to flatten hiera_array into string
- **STRING** : *Empty by default*

#### cmdline_linux_extra
- Aditional parameters to add to CMDLINE_LINUX
- **Hiera array** : *Empty by default*

#### cmdline_linux_base
- Base parameters to add to CMDLINE_LINUX
- **STRING** : *OS specific*

#### timeout
- Number of seconds that menu will appear
- **STRING** : *5*

#### default
- Default boot entry. You probably don't want to change this.
- **STRING** : *saved*

#### terminal_output
- Terminal output.
- **STRING** : *console*

#### disable_recovery
- tbd
- **STRING** : *true*

#### disable_submeny
- tbd
- **STRING** : *true*

### Example
```ruby
class { 'grub2':
cmdline_linux_base => 'rd.lvm.lv=sysvg/lv_swap biosdevname=0 rd.lvm.lv=sysvg/lv_root rhgb quiet',
timeout => '5',
disable_recovery => 'true',
disable_submenu => 'true'
}
```
### Hiera support

This module also supports the configuration of the parameters it exposes
using Hiera. To set the value of `timeout` to `10`, you would use:
```yaml
grub2::timeout: 10
```
In adition to this, cmd_linux_extra is an hiera_array where setting can be
added at multiple levels in your Hiera files:
Level 1:
```yaml
grub2::cmdline_linux_extra:
- vga=normal
```
Level 2:
```yaml
grub2::cmdline_linux_extra:
- nomodeset
```
This would end up in 'vga=normal nomodset' being added to CMDLINE_LINUX.
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_quoted_booleans')
PuppetLint.configuration.relative = true
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp"]

desc "Run puppet in noop mode and check for syntax errors."
task :validate do
Dir['manifests/**/*.pp'].each do |path|
sh "puppet parser validate --noop #{path}"
end
end

task :default => [:spec, :lint]
85 changes: 85 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# == Class: grub2
#
# See README for documentation
#
# === Authors
#
# Robert Hallgren <[email protected]>
#
# === Copyright
#
# Copyright 2016 Ericsson AB, unless otherwise noted.
#

class grub2 (
$efi_enabled = $grub2::params::efi_enabled,
$config_template = $grub2::params::config_template,
$users_template = $grub2::params::users_template,
$superuser_name = $grub2::params::superuser_name,
$superuser_pw_clear = $grub2::params::superuser_pw_clear,
$superuser_pw_pbkdf2 = $grub2::params::superuser_pw_pbkdf2,
$cmdline_linux_base = $grub2::params::cmdline_linux_base,
$all_cmdline_linux_extra = $grub2::params::all_cmdline_linux_extra,
$timeout = $grub2::params::timeout,
$default = $grub2::params::default,
$savedefault = $grub2::params::savedefault,
$serial_command = $grub2::params::serial_command,
$terminal = $grub2::params::terminal,
$terminal_input = $grub2::params::terminal_input,
$terminal_output = $grub2::params::terminal_output,
$disable_recovery = $grub2::params::disable_recovery,
$disable_submenu = $grub2::params::disable_submenu,
) inherits grub2::params {

if ($::operatingsystem == 'RedHat' and $::operatingsystemmajrelease == '7') {

$mkconfig_output_bios = '/boot/grub2/grub.cfg'
$mkconfig_output_efi = '/boot/efi/EFI/redhat/grub.cfg'

if ($efi_enabled == true) {
$mkconfig_output = $mkconfig_output_efi
}
else {
$mkconfig_output = $mkconfig_output_bios
}

file {'/etc/default/grub':
ensure => present,
content => template($config_template),
owner => 'root',
group => 'root',
mode => '0644',
notify => Exec['mkconfig_grub2'],
}

file {'/etc/sysconfig/grub':
ensure => 'link',
target => '/etc/default/grub',
require => File['/etc/default/grub'],
}

if ($superuser_name != undef) {
if ($superuser_pw_pbkdf2 != undef or $superuser_pw_clear != undef) {
file {'/etc/grub.d/01_users':
ensure => present,
content => template($users_template),
owner => 'root',
group => 'root',
mode => '0750',
notify => Exec['mkconfig_grub2'],
}
}
}


exec {'mkconfig_grub2':
command => "/usr/sbin/grub2-mkconfig --output=${mkconfig_output}",
refreshonly => true,
}
} else {
notify {"This grub2 module supports RedHat 7, you are running ${::operatingsystem} ${::operatingsystemmajrelease}":}
}
}



41 changes: 41 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# == Class: grub2::params
#
# See README for documentation
#
# === Authors
#
# Robert Hallgren <[email protected]>
#
# === Copyright
#
# Copyright 2016 Ericsson AB, unless otherwise noted.
#

class grub2::params {
$config_template = 'grub2/grub.erb'
$users_template = 'grub2/01_users.erb'
$all_cmdline_linux_extra = hiera_array('grub2::cmdline_linux_extra',[])

if defined('kdump') {
include kdump
$cmdline_linux_crashkernel = $kdump::grub2_crashkernel
}

if ($::operatingsystem == 'RedHat' and $::operatingsystemmajrelease == '7') {
$efi_enabled = false
$cmdline_linux_base = 'rd.lvm.lv=sysvg/lv_swap biosdevname=0 rd.lvm.lv=sysvg/lv_root rhgb quiet'
$timeout = '5'
$default = 'saved'
$savedefault = undef
$serial_command = undef
$terminal = undef
$terminal_input = undef
$terminal_output = 'console'
$disable_recovery = 'true'
$disable_submenu = 'true'
$superuser_name = undef
$superuser_pw_clear = undef
$superuser_pw_pbkdf2 = undef
}
}

22 changes: 22 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "erobhal-grub2",
"version": "1.0.15",
"author": "Robert Hallgren",
"summary": "Handle grub2 on Linux",
"license": "Apache 2.0",
"source": "[email protected]:/erobhal/puppet-module-grub2.git",
"project_page": "https://github.com/erobhal/puppet-module-grub2",
"issues_url": "https://github.com/erobhal/puppet-module-grub2/issues",
"dependencies": [
{
"name": "puppetlabs-stdlib",
"version_range": ">= 1.0.0"
}
],
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": ["7"]
}
]
}
Loading

0 comments on commit 02af515

Please sign in to comment.