I installed Puppet 3.1.1 on an Ubuntu Server.
My manifests folder looked like this:
├── nodes
│ └── test1.pp
└── site.pp
The content of site.pp was:
# site.pp
import "nodes/*.pp"
Node test1 worked OK.
Then I created a new file named test2.pp
. The content was the same as test1.pp except for the node name, and I added it into the nodes folder.
So the manifests folder became this:
├── nodes
│ ├── test1.pp
│ └── test2.pp
└── site.pp
I then ran puppet agent --test
on node test2.
The agent could exchange SSL keys with the puppet master, but I got an error message:
Could not find default node or by name with test2
If I don't create a new test2.pp
file, and just add the content into the test1.pp
file, no error appears.
So I am thinking Puppet will not dynamically import a new pp file after the puppet master has been started.
Is is possible to define nodes in individual pp files and dynamically import them?
Glad for any suggestions.
The content of the two pp files:
node 'test1' {
include tmp::params
tmp::gtp { 'node1':
name => 'node1',
version => '6.0.0.0',
ip => '168.1.193.97',
port => '1255',
}
}
node 'test2' {
include tmp::params
tmp::gtp { 'node2':
name => 'node2',
version => '6.0.0.0',
ip => '168.1.193.98',
port => '1255',
}
}
Best Answer
I'd recommend moving away from manifest node definitions to Hiera. You'll need to tweak things a bit to move away from having that defined type called directly from your node, but it looks like that isn't being used multiple times in a catalog anyway, so conversion to a class should work fine.
So with a
hiera.yaml
like this..And a
site.pp
with just:..your nodes will be read from YAML files in
/etc/puppet/hieradata
. For example's sake we'll say that you wanttmp::params
on every node reporting to Puppet, but maybe you wanttmp::gtp
just on certain nodes. And you want to centrally define theversion
parameter, but leave the other parameters to be set per-node. So we'll puttmp::params
and theversion
parameter/etc/puppet/hieradata/common.yaml
:Then you'll have a file for each node.
/etc/puppet/hieradata/test1.yaml
:/etc/puppet/hieradata/test2.yaml
:And yes, it'll pick up changes to the Hiera files without a service restart. Seem like about what you need?
Edit: to use Hiera to set up multiple instances of a defined type, you'll want to do something like this:
/etc/puppet/hieradata/test1.yaml
:/etc/puppet/modules/gtpsetup/manifests/init.pp
: