voxpupuli / puppet-systemd

Puppet module to manage systemd
https://forge.puppet.com/puppet/systemd
Apache License 2.0
54 stars 142 forks source link

Allow specifying multiple Environment variable #442

Closed qdii closed 6 months ago

qdii commented 6 months ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

    systemd::manage_unit { 'remote-decrypt-containerd.service':
      unit_entry    => {
        'Description' => 'Decrypts and unlock containerd',
      },
      service_entry => {
        'Type'        => 'simple',
        'ExecStart'   => 'remote-decrypt',
        'Environment' => 'URL=https://foo.bar.com/key',
        'Environment' => 'DEVICE=/dev/nvme0n1p1',
        'Environment' => 'VOLUME_NAME=containerd'
        ],
      },
      install_entry => {
        'WantedBy' => 'multi-user.target',
      },
    }

What are you seeing

The service file created as a result only contains one entry:

[Unit]
Description=Decrypts and unlock containerd

[Service]
Type=simple
ExecStart=remote-decrypt
Environment=VOLUME_NAME=containerd

[Install]
WantedBy=multi-user.target

What behaviour did you expect instead

I'd expect to see 3 Environment= lines

Any additional information you'd like to impart

I also tried the following syntax, to no avail


'Environment' => [
  'URL=https://foo.bar.com/key',
  'DEVICE=/dev/nvme0n1p1'
  'VOLUME_NAME=containerd'
]
TheMeier commented 6 months ago

The array form is explicitly tested in https://github.com/voxpupuli/puppet-systemd/blob/master/spec/defines/manage_unit_spec.rb#L41-L42

In your sample there is an error (extra ] line 11)

Running this code

include systemd

systemd::manage_unit { 'remote-decrypt-containerd.service':
  unit_entry    => {
    'Description' => 'Decrypts and unlock containerd',
  },
  service_entry => {
    'Type'        => 'simple',
    'ExecStart'   => 'remote-decrypt',
    'Environment' => ['URL=https://foo.bar.com/key','DEVICE=/dev/nvme0n1p1','VOLUME_NAME=containerd'],
  },
  install_entry => {
    'WantedBy' => 'multi-user.target',
  },
}

Does produce this result:

# Deployed with puppet
#

[Unit]
Description=Decrypts and unlock containerd

[Service]
Type=simple
ExecStart=remote-decrypt
Environment=URL=https://foo.bar.com/key
Environment=DEVICE=/dev/nvme0n1p1
Environment=VOLUME_NAME=containerd

[Install]
WantedBy=multi-user.target

Please verify that you are actually using the correct module version, also you put the module version under Puppet

qdii commented 6 months ago

Ahh indeed I had version 4.2.0 installed. Once upgrading to 6.6.0 the syntax worked. Thanks!