Skip to content

Commit

Permalink
Add /etc/sysconfig/haproxy(instance_name) support (#242)
Browse files Browse the repository at this point in the history
* add sysconfig_options param for /etc/sysconfig/haproxy

* fix

* add comment/readme
  • Loading branch information
Matt authored and bmjen committed Jun 9, 2016
1 parent 81afceb commit 4512ff4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ Main class, includes all other classes.

* `service_options`: Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.

* `sysconfig_options`: Contents for the `/etc/sysconfig/haproxy` file on RedHat(-based) systems. Defaults to OPTIONS="" on RedHat(-based) systems and is ignored on others

* `config_dir`: Path to the directory in which the main configuration file `haproxy.cfg` resides. Will also be used for storing any managed map files (see [`haproxy::mapfile`](#define-haproxymapfile). Default depends on platform.

#### Class: `haproxy::globals`
Expand Down
33 changes: 16 additions & 17 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
# [*service_options*]
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
#
# [*service_options*]
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
#
# [*service_options*]
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
# [*sysconfig_options*]
# Contents for the `/etc/sysconfig/haproxy` file on RedHat(-based) systems. Defaults to OPTIONS="" on RedHat(-based) systems and is ignored on others
#
# [*global_options*]
# A hash of all the haproxy global options. If you want to specify more
Expand Down Expand Up @@ -107,6 +104,7 @@
$service_ensure = 'running',
$service_manage = true,
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
$global_options = $haproxy::params::global_options,
$defaults_options = $haproxy::params::defaults_options,
$merge_options = $haproxy::params::merge_options,
Expand Down Expand Up @@ -162,18 +160,19 @@
}

haproxy::instance{ $title:
package_ensure => $_package_ensure,
package_name => $package_name,
service_ensure => $_service_ensure,
service_manage => $_service_manage,
global_options => $global_options,
defaults_options => $defaults_options,
restart_command => $restart_command,
custom_fragment => $custom_fragment,
config_dir => $config_dir,
config_file => $config_file,
merge_options => $merge_options,
service_options => $service_options,
package_ensure => $_package_ensure,
package_name => $package_name,
service_ensure => $_service_ensure,
service_manage => $_service_manage,
global_options => $global_options,
defaults_options => $defaults_options,
restart_command => $restart_command,
custom_fragment => $custom_fragment,
config_dir => $config_dir,
config_file => $config_file,
merge_options => $merge_options,
service_options => $service_options,
sysconfig_options => $sysconfig_options,
}

}
36 changes: 19 additions & 17 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,19 @@
# call haproxy::instance_service.
#
define haproxy::instance (
$package_ensure = 'present',
$package_name = undef,
$service_ensure = 'running',
$service_manage = true,
$global_options = undef,
$defaults_options = undef,
$restart_command = undef,
$custom_fragment = undef,
$config_dir = undef,
$config_file = undef,
$merge_options = $haproxy::params::merge_options,
$service_options = $haproxy::params::service_options,
$package_ensure = 'present',
$package_name = undef,
$service_ensure = 'running',
$service_manage = true,
$global_options = undef,
$defaults_options = undef,
$restart_command = undef,
$custom_fragment = undef,
$config_dir = undef,
$config_file = undef,
$merge_options = $haproxy::params::merge_options,
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
) {

if $service_ensure != true and $service_ensure != false {
Expand Down Expand Up @@ -211,11 +212,12 @@
package_ensure => $package_ensure,
}
haproxy::service { $title:
instance_name => $instance_name,
service_ensure => $service_ensure,
service_manage => $service_manage,
restart_command => $restart_command,
service_options => $service_options,
instance_name => $instance_name,
service_ensure => $service_ensure,
service_manage => $service_manage,
restart_command => $restart_command,
service_options => $service_options,
sysconfig_options => $sysconfig_options,
}

if $package_ensure == 'absent' or $package_ensure == 'purged' {
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$merge_options = false

$service_options = "ENABLED=1\n" # Only used by Debian.
$sysconfig_options = 'OPTIONS=""' #Only used by Redhat/CentOS etc

case $::osfamily {
'Archlinux', 'Debian', 'Redhat', 'Gentoo', 'Suse' : {
Expand Down
7 changes: 7 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$service_manage,
$restart_command = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
) {
if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
Expand All @@ -17,6 +18,12 @@
before => Service[$instance_name],
}
}
if ($::osfamily == 'Redhat') {
file {"/etc/sysconfig/${instance_name}":
content => $sysconfig_options,
before => Service[$instance_name],
}
}

$_service_enable = $service_ensure ? {
'running' => true,
Expand Down
4 changes: 4 additions & 0 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@
let(:facts) do
{ :osfamily => 'RedHat' }.merge default_facts
end
it 'should manage haproxy sysconfig options' do
subject.should contain_file('/etc/sysconfig/haproxy-group1')
verify_contents(catalogue, '/etc/sysconfig/haproxy-group1', ['OPTIONS=""'])
end
end
end
end
Expand Down

0 comments on commit 4512ff4

Please sign in to comment.