Ask Your Question
0

string based from two hiera lookups?

asked 2017-05-31 12:32:02 -0500

minimike gravatar image

updated 2017-05-31 12:35:37 -0500

Hi there

How could I write a string based from two hiera-lookups with an @ un the middle?

something like hiera('rabbituser')@hiera('controlnode') should give me for example elmer_fudd@runrabbitrun as string

class profiles::rabbitmq {

  include ::rabbitmq

  rabbitmq_user { hiera('rabbit_user'):
   admin => false,
   password => hiera('rabbit_password'),
  }


  rabbitmq_user_permissions { "hiera('rabbit_user')@hiera('rabbit_node')":
   configure_permission => '.*',
   read_permission => '.*',
   write_permission => '.*',
  }
}

I've tried also "hiera('rabbituser')"@"hiera('rabbitnode')": but everything what i tried gives me an

Server Error: Syntax error at '@' at

thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-05-31 18:04:03 -0500

Red Cricket gravatar image

updated 2017-06-01 10:44:51 -0500

It is not good form to call the hiera() function from within a puppet manifest. lhttps://docs.puppet.com/puppet/4.10/style_guide.html#hiera

Why not use class parameters for this? You are already using hiera .. so in your hiera you would have:

rabbit_user: 'whatever'
rabbit_password: 'whatever'
rabbit_node: 'whatever'
profiles::rabbitmq::rabbit_user: "%{hiera('rabbit_user')}"
profiles::rabbitmq::rabbit_password: "%{hiera('rabbit_password')}"
profiles::rabbitmq::rabbit_node: "%{hiera('rabbit_node')}"

Then your puppet code would look like:

class profiles::rabbitmq (
   $rabbit_user,
   $rabbit_password,
   $rabbit_node,
) {

  include ::rabbitmq

  rabbitmq_user { $rabbit_user:
   admin => false,
   password => $rabbit_password,
  }


  rabbitmq_user_permissions { "${rabbit_user}@${rabbit_node}":
   configure_permission => '.*',
   read_permission => '.*',
   write_permission => '.*',
  }
}
edit flag offensive delete link more
0

answered 2017-06-01 10:30:47 -0500

minimike gravatar image

updated 2017-06-01 10:32:15 -0500

Hi

Thank you about your hint. I got it running now

class profiles::rabbitmq (
  $rabbit_user = hiera('rabbit_user'),
  $rabbit_password = hiera('rabbit_password'),
  $rabbit_node = hiera('rabbit_vhost')
) {

  include ::rabbitmq

  rabbitmq_user { $rabbit_user:
    admin    => false,
    password => $rabbit_password,
  }


  rabbitmq_user_permissions { "${rabbit_user}@${rabbit_vhost}":
    configure_permission => '.*',
    read_permission      => '.*',
    write_permission     => '.*',
  }
}

I'm doing this because I didn't want double coude inside my yaml files

edit flag offensive delete link more

Comments

I am not sure if you are trying to say you "didn't want double colons" or "didn't want double code" in your yaml file.

Red Cricket gravatar imageRed Cricket ( 2017-06-01 10:39:53 -0500 )edit
1

For the former, there is nothing wrong with having double colons in your yaml file, but the Puppet language style guide does discourage the use of the hiera() function in puppet your puppet code.

Red Cricket gravatar imageRed Cricket ( 2017-06-01 10:40:14 -0500 )edit

For the later, you can use the hiera() function in your yaml file (i.e. profile::rabbitmq::rabbit_user: "%{hiera('rabbit_user')}") ... I've update my answer below to reflect this.

Red Cricket gravatar imageRed Cricket ( 2017-06-01 10:41:59 -0500 )edit

Sorry I'm not an native english speaker ;) I mean double colons. About the syntax double colons are proper. But they confusing people by reading. Because they are two defininitons about the same present.

minimike gravatar imageminimike ( 2017-06-01 10:44:18 -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: 2017-05-31 12:32:02 -0500

Seen: 48 times

Last updated: Jun 01