Ask Your Question
0

hiera array/hash lookup help [closed]

asked 2015-09-01 22:17:08 -0600

winningpanthers gravatar image

updated 2015-09-02 13:11:55 -0600

ramindk gravatar image

I have the below code which works fine, I would like to put the "mything" hash in the hiera. and I would like the same functionality with code with hiera. can you please help?

class testcode {
  define mything(
     $directory,
     $portnumber,
  ) {

    file { "/tmp/${directory}.${portnumber}":
        ensure => directory
    }
  }

  mything {
    "k1" : directory => "CAA", portnumber => "8008";
    "k2" : directory => "BBB", portnumber => "9009";
    "k3" : directory => "CCC", portnumber => "1001";
  }
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by winningpanthers
close date 2015-09-03 06:49:05.501965

2 Answers

Sort by » oldest newest most voted
1

answered 2015-09-02 14:08:45 -0600

Hi,

You can go to Hiera lookup type.

For your specific case, you can translate:

mything {
  "k1" : directory => "CAA", portnumber => "8008";
  "k2" : directory => "BBB", portnumber => "9009";
  "k3" : directory => "CCC", portnumber => "1001";
}

with

k1:
  directory: CAA
  portnumber: 8008
k2: 
 directory: BBB
 portnumber: 9009
k3: 
  directory: CCC
  portnumber: 1001

Regards, Rudy

edit flag offensive delete link more

Comments

thanks. I am trying the below code now: It works in 3.8 but not in 4.2. In 4.2 i am getting this error. Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, Puppet::Parser::AST::Resource failed with error ArgumentErro

winningpanthers gravatar imagewinningpanthers ( 2015-09-02 15:19:04 -0600 )edit
0

answered 2015-09-02 15:19:11 -0600

winningpanthers gravatar image

thanks.

I am trying the below code now: It works in 3.8 but not in 4.2. In 4.2 i am getting this error. Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type myhash at /opt/puppetlabs/puppet/modules/testcode/manifests/init.pp:15:16 on node 10.64.81.235 Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run


class testcode { #$myhash = hierahash('testcode::mything') # notify { "The value of configfile: ${myhash}": }

define myhash($directory, $portnumber) { file{"/tmp/t1${directory}.${portnumber}": ensure => directory }

     notify { "currently looping PORTNUMBER $directory:$portnumber": }
     # notify { "currently looping PORTNUMBER $portnumber": }
       }
       $my_hash = hiera_hash('testcode::mything')

           create_resources( myhash, $my_hash )

}


can you please help?

edit flag offensive delete link more

Comments

Please give us more détails next time. Anyway, your 'define myhash' seems to be in the 'testcode' module so you should replace it with 'define testcode::myhash' and put it in /opt/.../testcode/manifests/myhash.pp . Otherwise, mark this ticket as answered and open a new ticket for this new problem.

ryayon gravatar imageryayon ( 2015-09-03 04:03:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-01 22:15:50 -0600

Seen: 299 times

Last updated: Sep 02 '15