forked from thias/puppet-sysctl
-
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.
Sysctl class separated from the resource
Sysctl class is now used only for loading values from Hiera. Indiviaual sysctl variables (values) are set via sysctl::variable defined type. This should also fix the problem with create_resources(sysctl), described in thias#16
- Loading branch information
Pavel Smolka
committed
Nov 11, 2014
1 parent
2653e54
commit 467154e
Showing
8 changed files
with
135 additions
and
109 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
spec/fixtures | ||
pkg/* | ||
|
||
.idea |
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 |
---|---|---|
@@ -1,89 +1,7 @@ | ||
# Define: sysctl | ||
# | ||
# Manage sysctl variable values. | ||
# | ||
# Parameters: | ||
# $value: | ||
# The value for the sysctl parameter. Mandatory, unless $ensure is 'absent'. | ||
# $prefix: | ||
# Optional prefix for the sysctl.d file to be created. Default: none. | ||
# $ensure: | ||
# Whether the variable's value should be 'present' or 'absent'. | ||
# Defaults to 'present'. | ||
# | ||
# Sample Usage : | ||
# sysctl { 'net.ipv6.bindv6only': value => '1' } | ||
# | ||
define sysctl ( | ||
$ensure = undef, | ||
$value = undef, | ||
$prefix = undef, | ||
$suffix = '.conf', | ||
$comment = undef, | ||
$content = undef, | ||
$source = undef, | ||
) { | ||
# Manages a set of sysctl values from Hiera config (sysctl::base::values) | ||
class sysctl { | ||
|
||
include '::sysctl::base' | ||
|
||
# If we have a prefix, then add the dash to it | ||
if $prefix { | ||
$sysctl_d_file = "${prefix}-${title}${suffix}" | ||
} else { | ||
$sysctl_d_file = "${title}${suffix}" | ||
} | ||
|
||
# If we have an explicit content or source, use them | ||
if $content or $source { | ||
$file_content = $content | ||
$file_source = $source | ||
} else { | ||
$file_content = template("${module_name}/sysctl.d-file.erb") | ||
} | ||
|
||
if $ensure != 'absent' { | ||
|
||
# Present | ||
|
||
# The permanent change | ||
file { "/etc/sysctl.d/${sysctl_d_file}": | ||
ensure => $ensure, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0644', | ||
content => $file_content, | ||
source => $file_source, | ||
notify => [ | ||
Exec["sysctl-${title}"], | ||
Exec["update-sysctl.conf-${title}"], | ||
], | ||
} | ||
|
||
# The immediate change + re-check on each run "just in case" | ||
exec { "sysctl-${title}": | ||
command => "/sbin/sysctl -p /etc/sysctl.d/${sysctl_d_file}", | ||
refreshonly => true, | ||
require => File["/etc/sysctl.d/${sysctl_d_file}"], | ||
} | ||
|
||
# For the few original values from the main file | ||
exec { "update-sysctl.conf-${title}": | ||
command => "sed -i -e 's#^${title} *=.*#${title} = ${value}#' /etc/sysctl.conf", | ||
path => [ '/usr/sbin', '/sbin', '/usr/bin', '/bin' ], | ||
refreshonly => true, | ||
onlyif => "grep -E '^${title} *=' /etc/sysctl.conf", | ||
} | ||
|
||
} else { | ||
|
||
# Absent | ||
# We cannot restore values, since defaults can not be known... reboot :-/ | ||
|
||
file { "/etc/sysctl.d/${sysctl_d_file}": | ||
ensure => absent, | ||
} | ||
|
||
} | ||
create_resources(sysctl::variable, hiera_hash('sysctl::base::values')) | ||
|
||
} | ||
|
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,85 @@ | ||
# Define: sysctl::variable | ||
# | ||
# Manage sysctl variable values. | ||
# | ||
# Parameters: | ||
# $value : The value for the sysctl parameter. Mandatory, unless $ensure is 'absent'. | ||
# $prefix : Optional prefix for the sysctl.d file to be created. Default: none. | ||
# $ensure : Whether the variable's value should be 'present' or 'absent'. | ||
# | ||
# Sample Usage : | ||
# sysctl::variable { 'net.ipv6.bindv6only': value => '1' } | ||
# | ||
define sysctl::variable ( | ||
$ensure = present, | ||
$value = undef, | ||
$prefix = undef, | ||
$suffix = '.conf', | ||
$comment = undef, | ||
$content = undef, | ||
$source = undef, | ||
) { | ||
|
||
include ::sysctl::base | ||
|
||
# If we have a prefix, then add the dash to it | ||
if $prefix { | ||
$sysctl_d_file = "${prefix}-${title}${suffix}" | ||
} else { | ||
$sysctl_d_file = "${title}${suffix}" | ||
} | ||
|
||
# If we have an explicit content or source, use them | ||
if $content or $source { | ||
$file_content = $content | ||
$file_source = $source | ||
} else { | ||
$file_content = template("${module_name}/sysctl.d-file.erb") | ||
} | ||
|
||
if $ensure != 'absent' { | ||
|
||
# Present | ||
|
||
# The permanent change | ||
file { "/etc/sysctl.d/${sysctl_d_file}": | ||
ensure => $ensure, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0644', | ||
content => $file_content, | ||
source => $file_source, | ||
notify => [ | ||
Exec["sysctl-${title}"], | ||
Exec["update-sysctl.conf-${title}"], | ||
], | ||
} | ||
|
||
# The immediate change + re-check on each run "just in case" | ||
exec { "sysctl-${title}": | ||
command => "/sbin/sysctl -p /etc/sysctl.d/${sysctl_d_file}", | ||
refreshonly => true, | ||
require => File["/etc/sysctl.d/${sysctl_d_file}"], | ||
} | ||
|
||
# For the few original values from the main file | ||
exec { "update-sysctl.conf-${title}": | ||
command => "sed -i -e 's#^${title} *=.*#${title} = ${value}#' /etc/sysctl.conf", | ||
path => [ '/usr/sbin', '/sbin', '/usr/bin', '/bin' ], | ||
refreshonly => true, | ||
onlyif => "grep -E '^${title} *=' /etc/sysctl.conf", | ||
} | ||
|
||
} else { | ||
|
||
# Absent | ||
# We cannot restore values, since defaults can not be known... reboot :-/ | ||
|
||
file { "/etc/sysctl.d/${sysctl_d_file}": | ||
ensure => absent, | ||
} | ||
|
||
} | ||
|
||
} | ||
|
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,33 @@ | ||
{ | ||
"description": "Manage sysctl variable values.", | ||
"dependencies": [ | ||
|
||
], | ||
"name": "thias-sysctl", | ||
"project_page": "https://github.com/thias/puppet-sysctl", | ||
"license": "Apache 2.0", | ||
"source": "git://github.com/thias/puppet-sysctl", | ||
"author": "Matthias Saou", | ||
"summary": "Sysctl module", | ||
"types": [ | ||
|
||
], | ||
"checksums": { | ||
"tests/base.pp": "1ba89838432dbc94339097327c19ae3d", | ||
"ChangeLog": "c9f87a37f83809e6d348735bae6de409", | ||
"manifests/base.pp": "be6f023ad7e949a72f2b80115f812f9c", | ||
"tests/init.pp": "e70e5327b9840b44699bb7fae71d47cd", | ||
"Modulefile": "502d97ec47ecb5e7d39771a993d8d90f", | ||
"spec/defines/sysctl_init_spec.rb": "21d524df70961750cb22f6b83349093e", | ||
"spec/spec_helper.rb": "3ea886dd135e120afa31e0aab12e85b0", | ||
"Gemfile": "3ad486d60d90bfe4395b368b95481e01", | ||
"LICENSE": "99219472697a01561e7630d63aaecdc1", | ||
"README.md": "eecd73855d8815a56cbf13de841208f5", | ||
"manifests/params.pp": "d9387d767c84b0bb0213f82267e186aa", | ||
"Rakefile": "ab253b919e7093c2a5eb7adf0e39ffbc", | ||
"templates/sysctl.d-file.erb": "47e03b3e2b70bc7586271be8b9a6473d", | ||
"spec/classes/sysctl_base_spec.rb": "6241cf3e290871c00b1bb3bbd5490108", | ||
"manifests/init.pp": "1fbf64472b67ecceeffde36b91145884" | ||
}, | ||
"version": "1.0.0" | ||
} |