Dependencies with Hiera and create_resources.

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

not find
1
2
3
4
5
6
7
8
9
10
11
12
13
dependency``` error message will be displayed.
``` ruby site.pp
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