Ask Your Question

Why is the variable value empty ?

asked 2016-10-21 09:56:44 -0500

SKA gravatar image

Hi, we read hiera data in a variable. Within the loop we can see the value, when we exit the loop the variable sshvalues is empty. Why and how to fix ?

$allkeys = hiera('rootkeys') $allkeys.each | $userid | { $sshvalues = $userid['pubkey'] notify {"SSHValue: ${sshvalues}":} --> Value is shown }

notify { "All Keys: ${sshvalues}":} --> Value is empty

Thanks a lot Sven

edit retag flag offensive close merge delete


You should rephrase your question to ask about what you're trying to accomplish. It appears from your code that you're trying to create and array of ssh keys, but you are simply re-assigning the variable repeatedly.

lavaman gravatar imagelavaman ( 2016-10-21 13:44:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-21 18:07:26 -0500

each returns the values it iterates over unchanged, where map returns the data with the applied changes:

$all_keys = hiera('rootkeys')

$ssh_values = $ | $uid | {

notify { "${ssh_values}": }

more on lambdas in the documentation

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


Asked: 2016-10-21 09:56:44 -0500

Seen: 41 times

Last updated: Oct 21 '16