From 4435e1087f41c432e4a785611a6996092de37299 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Fri, 6 Mar 2015 20:10:54 -0500 Subject: [PATCH] Allow to configure sysctl values This patch allows to customize sysctl values on all nodes, by defining the values in Hiera directly. Change-Id: Iab8b2f8559d6748f77630d68c48aebed90cf07ec --- manifests/init.pp | 18 ++++++++++++++++++ spec/classes/cloud_init_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index bba4e127..fbfbac88 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -75,6 +75,19 @@ # }, # } # +# [*sysctl*] +# (optional) Set of sysctl values to set. +# Defaults {} +# Example: +# { +# 'net.ipv4.ip_forward' => { +# 'value' => '1', +# }, +# 'net.ipv6.conf.all.forwarding => { +# 'value' => '1', +# }, +# } +# # [*manage_firewall*] # (optional) Completely enable or disable firewall settings # (false means disabled, and true means enabled) @@ -110,6 +123,7 @@ class cloud( $selinux_booleans = [], $selinux_modules = [], $limits = {}, + $sysctl = {}, $manage_firewall = false, $firewall_rules = {}, $purge_firewall_rules = false, @@ -161,6 +175,10 @@ This node is under the control of Puppet ${::puppetversion}. include ::limits create_resources('limits::limits', $limits) + # sysctl values + include ::sysctl::base + create_resources('sysctl::value', $sysctl) + # SELinux if $::osfamily == 'RedHat' { class {'cloud::selinux' : diff --git a/spec/classes/cloud_init_spec.rb b/spec/classes/cloud_init_spec.rb index 3d84eac9..ce3b671e 100644 --- a/spec/classes/cloud_init_spec.rb +++ b/spec/classes/cloud_init_spec.rb @@ -64,6 +64,28 @@ describe 'cloud' do end + context 'with explicit sysctl values' do + before :each do + params.merge!( :sysctl => { + 'net.ipv4.ip_forward' => { + 'value' => '1', + }, + 'net.ipv6.conf.all.forwarding' => { + 'value' => '1', + } + }) + end + + it { is_expected.to contain_sysctl('net.ipv4.ip_forward').with( + :val => '1', + ) } + it { is_expected.to contain_sysctl('net.ipv6.conf.all.forwarding').with( + :val => '1', + ) } + + end + + it {is_expected.to contain_file('/etc/motd').with( {:ensure => 'file'}.merge(file_defaults) )}