Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manage_unit service_entry Environment can't have multiple values #404

Closed
XDjackieXD opened this issue Jan 19, 2024 · 3 comments · Fixed by #409
Closed

manage_unit service_entry Environment can't have multiple values #404

XDjackieXD opened this issue Jan 19, 2024 · 3 comments · Fixed by #409

Comments

@XDjackieXD
Copy link

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 8.3.1
  • Ruby:
  • Distribution: Debian Bookworm
  • Module version: 6.3.0

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

  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,
  }

What are you seeing

An error during the puppet run (see output log)

What behaviour did you expect instead

A systemd service that contains multiple "Environment=" lines (Which is valid as per https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Environment)

Output log

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Manage_unit[test.service]: parameter 'service_entry' entry 'Environment' expects a String value, got Tuple (file: /etc/puppetlabs/code/environments/j_test/modules/profile/manifests/test/test.pp, line: 23) on node xxx
@moritzdietz
Copy link

I too just ran into this issue

@XDjackieXD
Copy link
Author

XDjackieXD commented Feb 2, 2024

I solved it this way:

$env = {
  "bla" => "foo",
  "bar" => "bla",
}
...
'Environment' => $env.map |$k, $v| { "\"${k}=${v}\"" }.join(" "),

not the nicest of all solutions but works and is readable enough.

As the proper solution would be pretty easy to do as far as I can tell I would still like to see this fixed in this repo.

@moritzdietz
Copy link

moritzdietz commented Feb 2, 2024

Ha! Thanks for that workaround, I'll give it a try. And yes, a proper solution like

Optional['Environment'] => String,

-   Optional['Environment']               => String,
+   Optional['Environment']               => Variant[String, Array[String]],

should suffice I would say. I'd open a PR but I don't know how to write the tests for it 🤷🏻

traylenator added a commit to traylenator/puppet-systemd that referenced this issue Feb 2, 2024
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
@traylenator traylenator added the bug Something isn't working label Feb 2, 2024
pfhonore pushed a commit to pfhonore/puppet-systemd that referenced this issue Feb 5, 2024
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
@bastelfreak bastelfreak added skip-changelog and removed bug Something isn't working labels Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants