0

I am trying to create an interface to pseudo-loop over a set of keys:values from my hiera yaml to update a config file with augeas

define augeas_config (
  $key,
  $value
)
{
  augeas{ "/var/MYCONF/MYCONF.def":
    lens => "/var/lib/puppet/lib/augeas/lenses/MYCONF.aug",
    incl => "/var/MYCONF/MYCONF.def",
    context => "/var/MYCONF/MYCONF.def",
    changes => [ "set $key $val" ],
  }
}

$augeas_files = hiera_hash('lib_BOX::MYCONF::config', {} )
validate_hash($augeas_files)

create_resources('augeas_config', $augeas_files)

where in my yaml keys:values to be updated are supposed to be in a hash like

lib_BOX::MYCONF::config:
  SITE_NAME: "TEST-SITE"
  OTHER_STUFF: "DEBUG"

So, the idea is to apply my augeas lense (not sure, if I really need 'context', when 'incl' has to be used with 'lens') for the pairs from my yaml.

However, puppet fails currently complaining about a string instead of an expected hash

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, can't convert String into Hash at /etc/puppet/environments/development/modules/lib_BOX/manifests/config.pp:28:3 on node MY.NODE.FOO

where line 28 is the one with "create_resources('augeas_config'...". Since I get a hash from hiera, I suppose something in my resource definition is broken, but I do not see what??

Maybe somebody has an idea for me?

Cheers and thanks, Thomas

THX
  • 553
  • 2
  • 8
  • 18

1 Answers1

0

Data in your yaml file is invalid. Change it to something like:

lib_BOX::MYCONF::config:
    first_aug:
        key: SITE_NAME
        value: "TEST-SITE"
    second_aug:
        key: OTHER_STUFF
        value : "DEBUG"

In addition you do not have to use hiera_hash. You can use just hiera. Please read about differences between hiera lookup functions and follow examples about lookup types. Probably you will also have to remove line validate_hash($augeas_files).

kkamil
  • 2,593
  • 11
  • 21