how would one go about setting up an override file...
# forge-modules
b
how would one go about setting up an override file for a service in systemd using hiera? i’d like an override file for elasticsearch, this is as far as i’ve gotten so far:
Copy code
systemd::dropin_file:
  unit: elasticsearch
  filename: override.conf
  content: "[Service]
  LimitMEMLOCK=infinity"
but sadly it doesn’t even try to create the file
the s is important 😉
b
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Expected value of type Hash, got String (file: /etc/puppetlabs/code/environments/test/modules/systemd/manifests/init.pp, line: 316, column: 12) on node at least i got a new error message so that’s progress 🙂
t
try
content: | ....
b
nope, that did not work either but as luck would have it i do have a file on hand that i can use instead. trying source:
nope, no dice
i’m an idiot, hold on. managed to remove the ever so important ‘s’ :)
Copy code
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Expected value of type Hash, got String (file: /etc/puppetlabs/code/environments/test/modules/systemd/manifests/init.pp, line: 316, column: 12) on node
the code:
Copy code
systemd::dropin_files:
  unit: elasticsearch
  filename: override.conf
  source: puppet:///modules/modulename/systemd/override.conf
t
b
i’m not trying to set up a timer so i don’t understand why that section is executed
Copy code
# @param unit The target unit file to create
# @param filename The filename of the drop in. The full path is determined using the path, unit and this filename.
# @param ensure the state of this dropin file
# @param path The main systemd configuration path
# @param selinux_ignore_defaults If Puppet should ignore the default SELinux labels.
# @param content The full content of the unit file (Mutually exclusive with `$source`)
# @param source The `File` resource compatible `source` Mutually exclusive with ``$content``
# @param target If set, will force the file to be a symlink to the given target (Mutually exclusive with both `$source` and `$content`
# @param owner The owner to set on the dropin file
# @param group The group to set on the dropin file
# @param mode The mode to set on the dropin file
# @param show_diff Whether to show the diff when updating dropin file
# @param notify_service Notify a service for the unit, if it exists
# @param daemon_reload Call systemd::daemon_reload
#
define systemd::dropin_file (
  Systemd::Unit                               $unit,
  Systemd::Dropin                             $filename                = $name,
  Enum['present', 'absent', 'file']           $ensure                  = 'present',
  Stdlib::Absolutepath                        $path                    = '/etc/systemd/system',
  Boolean                                     $selinux_ignore_defaults = false,
  Optional[Variant[String,Sensitive[String]]] $content                 = undef,
  Optional[String]                            $source                  = undef,
  Optional[Stdlib::Absolutepath]              $target                  = undef,
  String                                      $owner                   = 'root',
  String                                      $group                   = 'root',
  String                                      $mode                    = '0444',
  Boolean                                     $show_diff               = true,
  Boolean                                     $notify_service          = true,
  Boolean                                     $daemon_reload           = true,
)
i don’t see what’s supposed to be a hash in the hiera data
t
which version is that? see
metadata.json
b
7.1.0
b
that offset is wrong, let me double check what version we’re running
damn, that’s old, we’re running 3.10.0 and i was looking at the code for 7.1.0
t
lol
b
well the error message improved in 7.1.0 so that’s something at least:
Copy code
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Class[Systemd]:
  parameter 'dropin_files' entry 'unit' expects a Hash value, got String
  parameter 'dropin_files' entry 'filename' expects a Hash value, got String
  parameter 'dropin_files' entry 'source' expects a Hash value, got String (file: /etc/puppetlabs/code/environments/test/modules/elloselastic/manifests/hiera_config.pp, line: 10, column: 3) on node
tried this too:
Copy code
systemd::dropin_files:
  unit:
    elasticsearch
  filename:
    override.conf
  source:
    puppet:///modules/modulename/systemd/override.conf
but no joy there either
t
it should be:
Copy code
systemd::dropin_files:
  some_hash_key:
    unit:elasticsearch
    filename: override.conf
    source: puppet:///modules/modulename/systemd/override.conf
b
getting closer
Copy code
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Dropin_file[es_override]: parameter 'unit' expects a match for Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/], got 'elasticsearch' (file: /etc/puppetlabs/code/environments/test/modules/systemd/manifests/init.pp, line: 371) on node
t
well yes
elasticsearch.service
b
it worked!
Copy code
Notice: /Stage[main]/Systemd/Systemd::Dropin_file[es_override]/File[/etc/systemd/system/elasticsearch.service.d]/ensure: created
Notice: /Stage[main]/Systemd/Systemd::Dropin_file[es_override]/File[/etc/systemd/system/elasticsearch.service.d/override.conf]/ensure: defined content as '{sha256}7e42b2fde283c47ad0367f8bdbef4990cc2ea0dfdb1a1e78392233fc1d02afbb'
Info: /Stage[main]/Systemd/Systemd::Dropin_file[es_override]/File[/etc/systemd/system/elasticsearch.service.d/override.conf]: Scheduling refresh of Service[elasticsearch]
Info: /Stage[main]/Systemd/Systemd::Dropin_file[es_override]/File[/etc/systemd/system/elasticsearch.service.d/override.conf]: Scheduling refresh of Systemd::Daemon_reload[elasticsearch.service]
Info: Systemd::Daemon_reload[elasticsearch.service]: Scheduling refresh of Exec[systemd-elasticsearch.service-systemctl-daemon-reload]
Notice: /Stage[main]/Systemd/Systemd::Dropin_file[es_override]/Systemd::Daemon_reload[elasticsearch.service]/Exec[systemd-elasticsearch.service-systemctl-daemon-reload]: Triggered 'refresh' from 1 event
beautiful, thanks a bunch!