Skip to content

Commit

Permalink
Support multiple Environment Settings
Browse files Browse the repository at this point in the history
It was previously impossible to set more than one environment variable:

e.g.

```puppet
systemd::manage_unit { 'test.service':
  unit_entry    => {
    'Description' => 'Bla',
  },
  service_entry => {
    'Type'        => 'oneshot',
    'Environment' => [
      'bla=foo',
      'bar=bla',
    ],
    'ExecStart'   => '/usr/bin/true',
  },
  enable        => false,
  active        => false,
}
```

* Fixes voxpupuli#404
  • Loading branch information
traylenator committed Feb 2, 2024
1 parent 3eccd13 commit 5dc241e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ Struct[{
Optional['NotifyAccess'] => Enum['none', 'default', 'main', 'exec', 'all'],
Optional['OOMPolicy'] => Enum['continue', 'stop','kill'],
Optional['OOMScoreAdjust'] => Integer[-1000,1000],
Optional['Environment'] => String,
Optional['Environment'] => Variant[String[0],Array[String[1],1]],
Optional['EnvironmentFile'] => Variant[
Stdlib::Unixpath,Pattern[/-\/.+/],
Array[Variant[Stdlib::Unixpath,Pattern[/-\/.+/]],1],
Expand Down
3 changes: 3 additions & 0 deletions spec/defines/manage_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Type: 'oneshot',
ExecStart: '/usr/bin/doit.sh',
SyslogIdentifier: 'doit-backwards.sh',
Environment: ['bla=foo', 'foo=bla']
},
install_entry: {
WantedBy: 'multi-user.target',
Expand All @@ -36,6 +37,8 @@
with_content(%r{^DefaultDependencies=true$}).
with_content(%r{^\[Service\]$}).
with_content(%r{^SyslogIdentifier=doit-backwards\.sh$}).
with_content(%r{^Environment=bla=foo$}).
with_content(%r{^Environment=foo=bla$}).
with_content(%r{^\[Install\]$}).
with_content(%r{^Description=My great service$}).
with_content(%r{^Description=has two lines of description$}).
Expand Down
3 changes: 3 additions & 0 deletions spec/type_aliases/systemd_unit_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
it { is_expected.to allow_value({ 'ExecStart' => 'notabsolute.sh' }) }
it { is_expected.not_to allow_value({ 'ExecStart' => '*/wrongprefix.sh' }) }

it { is_expected.to allow_value({ 'Environment' => '' }) }
it { is_expected.to allow_value({ 'Environment' => 'FOO=BAR' }) }
it { is_expected.to allow_value({ 'Environment' => ['FOO=BAR', 'BAR=FOO'] }) }
it { is_expected.to allow_value({ 'EnvironmentFile' => '/etc/sysconfig/foo' }) }
it { is_expected.to allow_value({ 'EnvironmentFile' => '-/etc/sysconfig/foo' }) }
it { is_expected.to allow_value({ 'EnvironmentFile' => ['/etc/sysconfig/foo', '-/etc/sysconfig/foo-bar'] }) }
Expand Down
2 changes: 1 addition & 1 deletion types/unit/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
Optional['NotifyAccess'] => Enum['none', 'default', 'main', 'exec', 'all'],
Optional['OOMPolicy'] => Enum['continue', 'stop','kill'],
Optional['OOMScoreAdjust'] => Integer[-1000,1000],
Optional['Environment'] => String,
Optional['Environment'] => Variant[String[0],Array[String[1],1]],
Optional['EnvironmentFile'] => Variant[
Stdlib::Unixpath,Pattern[/-\/.+/],
Array[Variant[Stdlib::Unixpath,Pattern[/-\/.+/]],1],
Expand Down

0 comments on commit 5dc241e

Please sign in to comment.