0

I need to write multiple site.pp file for the same hosts. It gives me the following error

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Node 'default' is already defined at line 2; cannot redefine at line 2 on node node-002.example.com

For example :

My first site.pp

vi hosts-site.pp
default{
  }
 node "node-002.example.com" {
           ## Rules here to update /etc/hosts
         }

Next Site.pp with the same node but different operations .

 vi fstab-site.pp
default{
  }
 node "node-002.example.com" {
           ## Rules here to update /etc/fstab
         }   

How to achieve the same. We need to write multiple operations for the same nodes for which we need to maintain different site.pp

Zama Ques
  • 523
  • 1
  • 9
  • 24

1 Answers1

3

Puppet is not supposed to have multiples site.pp

If your goal is to apply manually one of your configuration, you can use the --tags option. By the way, you should configure your agent to act as noop so it will not apply your changes when you don't want it.

So you could have a site.pp like this :

node "node-002.example.com" {
  class {'hosts_configuration'}
  class {'fstab_configuration'}
}

Where hosts_configuration and fstab_configuration are modules that configures what you want.

Then, when you want to apply hosts configuration, you could use on your node-002

puppet agent -t --tags=hosts_configuration

And it will apply the needed configuration for hosts.

If you really want to have multiples site.pp, you can do this using environments:

https://docs.puppet.com/puppet/4.10/environments.html#about-environments

Wee
  • 702
  • 4
  • 10