-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# @summary Program definition | ||
# | ||
# A command to be executed by haproxy master process | ||
# | ||
# @see https://www.haproxy.com/documentation/haproxy-configuration-tutorials/programs/ | ||
# @example | ||
# haproxy::program { 'hello': | ||
# command => 'hello world', | ||
# } | ||
define haproxy::program ( | ||
String $command, | ||
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $user = undef, | ||
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $group = undef, | ||
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $options = undef, | ||
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
String $instance = 'haproxy', | ||
Check warning on line 15 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
|
||
Optional[Stdlib::Absolutepath] $config_file = undef, | ||
Check warning on line 16 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
|
||
) { | ||
# We derive these settings so that the caller only has to specify $instance. | ||
include haproxy::params | ||
|
||
if $instance == 'haproxy' { | ||
$instance_name = 'haproxy' | ||
$_config_file = pick($config_file, $haproxy::config_file) | ||
} else { | ||
$instance_name = "haproxy-${instance}" | ||
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl)) | ||
} | ||
|
||
concat::fragment { "${instance_name}-${name}_program": | ||
order => "40-program-${name}", | ||
target => $_config_file, | ||
content => epp('haproxy/haproxy_program.epp', { | ||
'name' => $name, | ||
'command' => $command, | ||
'user' => $user, | ||
'group' => $group, | ||
'options' => $options, | ||
}), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'haproxy::program' do | ||
let :pre_condition do | ||
'class{"haproxy": | ||
config_file => "/tmp/haproxy.cfg" | ||
} | ||
' | ||
end | ||
let(:facts) do | ||
{ | ||
concat_basedir: '/foo', | ||
os: { | ||
family: 'Debian' | ||
} | ||
} | ||
end | ||
|
||
context 'simple program' do | ||
let(:title) { 'hello' } | ||
let(:params) do | ||
{ | ||
command: 'echo "hello world"', | ||
} | ||
end | ||
|
||
it { | ||
is_expected.to contain_concat__fragment('haproxy-hello_program').with( | ||
'order' => '40-program-hello', | ||
'target' => '/tmp/haproxy.cfg', | ||
'content' => %r{command echo "hello world"}, | ||
) | ||
} | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
program <%= $name %> | ||
command <%= $command %> | ||
<% if $user { -%> | ||
user <%= $user %> | ||
<% } -%> | ||
<% if $group { -%> | ||
group $group | ||
<% } -%> | ||
<% if $options { -%> | ||
<%= $options %> | ||
<% } -%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type Haproxy::Programs = Hash[String, Struct[{ | ||
command => String[1], | ||
Optional[user] => String[1], | ||
Optional[group] => String[1], | ||
Optional[options] => String[1], | ||
Optional[instance] => String[1], | ||
Optional[config_file] => Stdlib::Absolutepath, | ||
}]] | ||
|