Ask Your Question
2

Trying to set dependencies with Hiera and create_resources

asked 2013-09-18 15:30:33 -0600

ramindk gravatar image

updated 2013-09-18 15:41:15 -0600

I'm trying to specify which service to notify for packages that are installed via a lookup in Hiera and then pushed through create_resources. The error on the agent is below. Looking on the master, it's doing a lookup properly. If I remove the notify line, everything works correctly minus the ordering. Setting ensure: 'present' or 'absent' always works.

modules/profile/manifests/varnish.pp

class profile::varnish {
  include ::varnish

  $mylibvmods = hiera('varnish::libvmods', {})
  create_resources(package, $mylibvmods)
}

hieradata/fe.yaml

---
apache::a2mods:
  expires: {}
varnish::libvmods:
  libvmod-cookie:
    notify: 'Class["varnish::service"]' # this does not work
    notify: Class["varnish::service"] # nor this ...
(more)
edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted
5

answered 2013-12-04 16:27:11 -0600

vicinus gravatar image

For require and before I can guarantee, that it's possible to configure them via hiera. I don't think there is a difference between require/before and notify/subscribe. Here an easy example how it works for require:

hiera:

files:
 '/tmp/a':
   ensure: present
   require: File[/tmp/b]
 '/tmp/b':
   ensure: present
   require: File[/tmp/a]

puppet:

puppet apply -e "create_resources('file', hiera_hash('files'))"
Error: Could not apply complete catalog: Found 1 dependency cycle:
(File[/tmp/a] => File[/tmp/b] => File[/tmp/a])

In your example the spelling of the resource is wrong. It must be absolutely identical to ... (more)

edit flag offensive delete link more
2

answered 2013-09-18 15:36:00 -0600

ramindk gravatar image

updated 2013-09-18 15:41:29 -0600

The solution to this problem is to realize that Hiera always returns a string and not the resource reference I was expecting. No matter how you're quoting it, Puppet will see it as

notify => 'Class[$class::$subclass]'

Instead of

notify => Class[$class::$subclass]

That is also the reason ensure worked normally. It expects a string.

There are a few solutions like use tags and then collecting them, but I solved it by setting default parameters for the create_resources to use when calling package.

modules/profile/manifests/varnish.pp

class profile::varnish {
  include ::varnish

  $defaults = {
    'notify' => Class['varnish::service'],
  }

  $mylibvmods ...
(more)
edit flag offensive delete link more
2

answered 2013-10-02 07:53:12 -0600

miked63017 gravatar image

If you are notifying only Classes speecifically you could get an array of classnames from hiera and do:

notify => Class[$arrayGottenFromHiera]
edit flag offensive delete link more

Comments

Nice and upvote for you. I'd really like to be able to adhoc require any resource type from keys which I think might be possible when Hiera 2.0 hits.

ramindk gravatar imageramindk ( 2013-10-02 12:22:45 -0600 )edit
1

answered 2014-07-26 20:45:43 -0600

bwarsing gravatar image

For anybody searching for Hiera YAML syntax for chaining multiple resources, 'before', 'after', 'subscribe' and 'require' accept an Array:

files:
  '/tmp/a':
      ensure: present
      require: File[/tmp/b]
  '/tmp/b':
      ensure: present
      require: File[/tmp/a]
  '/tmp/c':
      ensure: present
      require: 
          - File[/tmp/a]
          - File[/tmp/b]
edit flag offensive delete link more
0

answered 2016-10-15 17:13:35 -0600

jonhattan gravatar image

It seems this no longer works in puppet 4.x

edit flag offensive delete link more

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: 2013-09-18 15:30:33 -0600

Seen: 9,224 times

Last updated: Dec 04 '13