Ask Your Question
3

Problems creating Hiera hashes for create_resources

asked 2013-05-19 01:57:32 -0500

ramindk gravatar image

I'm moving my vhosts to Hiera and using create_resources to define them.

hieradata/frontend.yaml

---
apache::vhosts:
  - 'www.example.com'
  - 'stats.example.com'

manifests/nodes/frontend.pp

node /^fe\d+/ {

  $myvhosts = hiera('apache::vhosts')
  create_resources('apache::vhost', $myvhosts)
}

With this I get the following error:

Error 400 on SERVER: can't convert String into Hash at manifests/nodes/frontend.pp:4

At this point I realize I've got an array. I change my data to

hieradata/frontend.yaml

---
apache::vhosts:
  www.example.com:
  stats.example.com:

Now I get the following error:

Error 400 on SERVER: can't ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-05-19 02:04:54 -0500

ramindk gravatar image

updated 2013-09-18 15:22:49 -0500

Two fixes were required. First in my manifest I added a default empty hash to stop the catalog compile from failing if no vhosts were defined. While this didn't have anything to do with the original problem it stops possible problems in the future.

manifests/nodes/frontend.pp

node /^fe\d+/ {

  $myvhosts = hiera('apache::vhosts', {})
  create_resources('apache::vhost', $myvhosts)
}

Then I fixed the data in the same way by specifying empty values for my keys as needed. I believe that was why my attempt to make a hash was coming up nil, because I was only defining keys with ... (more)

edit flag offensive delete link more
1

answered 2013-09-18 17:23:24 -0500

Stefan gravatar image

I may be overlooking something here but your first example suggests that you would be fine with an array because you do not have any meaningful key-value-pairs. If that is the case, you don't rely on create_resources at all.

$myvhosts = hiera('apache::vhosts')
apache::vhost { $myvhosts: }
edit flag offensive delete link more

Comments

Sure that would work in the simple case, but that locks you into a particular data type. If your data changes, your code has to change which defeats the purpose ...(more)

ramindk gravatar imageramindk ( 2013-09-18 17:28:55 -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

Stats

Asked: 2013-05-19 01:57:32 -0500

Seen: 11,272 times

Last updated: Sep 18 '13