J'aime pas les piles

My lost place

Dependencies With Hiera and Create_resources.

| Comments

In a nodeless setup it is possible to manage dependencies between resources created by create_resources, but the syntax is quite strict and caused me some troubles. If the syntax is not correct the traditionnal Could not find dependency error message will be displayed.

site.pp
1
2
3
4
5
6
7
8
9
node default {
  hiera_include ('classes', [])

  $packages = hiera_hash('packages', {})
  create_resources('package', $packages)

  $services = hiera_hash('services', {})
  create_resources('service', $services)
}

The following won’t work:

common.yaml
1
2
3
4
services:
  mysql:
    ensure: 'running'
    require: Package['mysql-server']

Nor the following:

common.yaml
1
2
3
4
services:
  mysql:
    ensure: 'running'
    require: "Package['mysql-server']"

But the following two syntaxes will work:

common.yaml
1
2
3
4
5
6
7
8
9
10
---
classes:
  - 'puppet::agent'
packages:
  mysql-server:
    ensure: 'installed'
services:
  mysql:
    ensure: 'running'
    require: Package[mysql-server]
common.yaml
1
2
3
4
5
6
7
8
9
10
---
classes:
  - 'puppet::agent'
packages:
  mysql-server:
    ensure: 'installed'
services:
  mysql:
    ensure: 'running'
    require: 'Package[mysql-server]'

See a full example running in Vagrant at https://github.com/gwarf/puppet-vagrant-playground

Comments