Ask Your Question
0

Setting default value for a variable, in case lookup doesn't return anything

asked 2018-06-15 05:10:47 -0600

monalsharma gravatar image

Hi,

I have a code which work with puppet version 3 to set Password min length settings for the value 8 if Hiera can't find a value in data

$_passlen = hiera('entos_generic_harden::accounts::passlen',8)

The same code am migrating with Puppet version 4 as follows

$_passlen = lookup('entos_generic_harden::accounts::passlen', default_value => 8)

while applying the module am getting an error as below. Error: /Stage[main]/Entos_generic_harden::Accounts/Augeas[/etc/login.defs]: Could not evaluate: missing string argument 2 for set

kindly suggest how to set a default value on Puppet 4 version if Hiera can't find a value in data.

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-06-15 07:10:38 -0600

Mr_Sharma gravatar image

Hi Monal,

I think instead of using the lookup function we can rely on automatic parameter lookup which is quite simpler than this. Hence instead of using the above function you can do something similar to following:

class entos_generic_harden::accounts (
$passlen = 8,
$other   = "newvalue"
) {
//Resource definition
  }
}

and correspondingly you need to define the parameter value in your heira data yaml as:

---
entos_generic_harden::accounts::passlen: 8

Couple of references given below:

https://puppet.com/docs/hiera/3.3/puppet.html#puppet-4 

https://www.devco.net/archives/2016/03/13/the-puppet-4-lookup-function.php

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-15 05:10:47 -0600

Seen: 73 times

Last updated: Jun 15