Ask Your Question

proper way to define/lookup hash?

asked 2018-03-28 11:27:19 -0600

kmhuntly gravatar image

I have the following in my node yaml:

  - id: 'caspersb-sdns01'
    address: ''
  - id: 'caspersb-sdns02'
    address: ''

I'm trying to capture the value in a pp file with this:

$servers = lookup('profile::named::servers', {value_type => Hash[String, String], default_value => ''})

Then I have some iteration work in a template that would go through using server['id'], etc. However, when I run a test, this errors with "Expected hash., got tuple"

Am i defining the hash incorrectly or trying to access it incorrectly?

edit retag flag offensive close merge delete


The symbol - makes an array hence your expected hash got tuple error. If you want to make a hash you use soft tabs. like c4f4t0r suggested. However you do not need server1: you can make the id value the second level.

ffalor gravatar imageffalor ( 2018-04-01 17:28:11 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-03-30 03:50:26 -0600

c4f4t0r gravatar image

updated 2018-03-30 03:52:35 -0600

The error is clear, you don't have a have, try to use to check your yaml data, I think that you need something like this.

    id: 'caspersb-sdns01'
    address: ''
    id: 'caspersb-sdns02'
    address: ''
edit flag offensive delete link more


thank you, that does take care of it but it doesnt seem to actually populate the variable. if i add a notify to the manifest i get "$var" instead of the actual value of the variable.

kmhuntly gravatar imagekmhuntly ( 2018-03-30 07:23:13 -0600 )edit

one thing that I find useful is to do a yaml -> json transformation to verify how it looks, since I'm more familiar with the 'shape' of json than of yaml, particularly with arrays and hashes

DarylW gravatar imageDarylW ( 2018-03-30 08:07:50 -0600 )edit

@kmhuntly why you don't show your template?

c4f4t0r gravatar imagec4f4t0r ( 2018-03-31 07:21:30 -0600 )edit

here's what i'm using to lookup:

class named::config (
    $servers = lookup('profile::named::servers', {value_type => Hash, default_value => ''})

kmhuntly gravatar imagekmhuntly ( 2018-04-02 09:09:44 -0600 )edit

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: 2018-03-28 11:27:19 -0600

Seen: 66 times

Last updated: Mar 30