Ask Your Question
0

proper way to define/lookup hash?

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

kmhuntly gravatar image

I have the following in my node yaml:

profile::named::servers:
  - id: 'caspersb-sdns01'
    address: '192.168.20.6'
  - id: 'caspersb-sdns02'
    address: '192.168.20.7'

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

Comments

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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

c4f4t0r gravatar image

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

The error is clear, you don't have a have, try to use http://yaml-online-parser.appspot.com/ to check your yaml data, I think that you need something like this.

profile::named::servers:
  server1:
    id: 'caspersb-sdns01'
    address: '192.168.20.6'
  server2:
    id: 'caspersb-sdns02'
    address: '192.168.20.7'
edit flag offensive delete link more

Comments

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 -0500 )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 -0500 )edit

@kmhuntly why you don't show your template?

c4f4t0r gravatar imagec4f4t0r ( 2018-03-31 07:21:30 -0500 )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 -0500 )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

Stats

Asked: 2018-03-28 11:27:19 -0500

Seen: 61 times

Last updated: Mar 30