多个site.pp为相同的节点

我需要为同一主机编写多个site.pp文件。 它给了我以下错误

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 

例如 :

我的第一个site.pp

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

下一个Site.pp具有相同的节点但操作不同。

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

如何实现相同。 我们需要为需要维护不同site.pp的相同节点编写多个操作

木偶不应该有多个site.pp

如果您的目标是手动应用您的某个configuration,则可以使用–tags选项。 顺便说一下,您应该将您的代理configuration为noop,以便在您不需要时不会应用您的更改。

所以你可以有这样的site.pp:

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

其中hosts_configurationfstab_configuration是configuration你想要的模块。

然后,当你想应用主机configuration时,你可以在你的node-002上使用

 puppet agent -t --tags=hosts_configuration 

它将应用主机所需的configuration。

如果你真的想要多个site.pp,你可以使用环境来做到这一点:

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