Puppet:无法按名称找到默认节点

Puppet: Could not find default node by name with

我是木偶新手。首先,我安装并配置了人偶。 如果我检查我的主人的证书:

+ "puppet"                   (SHA256) FB:57:B2:B7:18:99:0F:15:DB:F0:E1:E8:12:31:99:75:BF:05:46:8D:78:A9:C4:DD:68:9E:A4:xxx (alt names: "DNS:puppet", "DNS:puppetmaster.example.com")
+ "puppetclient.example.com" (SHA256) 64:4F:0C:B2:EA:53:6B:2D:E3:5B:11:DB:80:E3:DF:AD:A6:AF:B5:B9:DB:05:6F:79:5D:E5:8Exxx

我尝试应用一些 site.pp。 这是我的 init.pp

class apache2 {
  package { 'apache2':
    ensure => installed,
  }

  service { 'apache2':
    ensure  => true,
    enable  => true,
    require => Package['apache2'],
  }
}

这是我的site.pp

node 'puppetclient.example.com' {
   include apache2
}

我尝试: sudo puppet apply site.pp 并且出现以下错误

Error: Could not find default node or by name with 'puppet, puppet.example.com, puppet.example' on node puppet
Error: Could not find default node or by name with 'puppet, puppet.example.com, puppet.example' on node puppet

它似乎试图在不存在的主机(可能是默认主机名)上执行我的 .pp。我究竟做错了什么。我希望它在我的 puppetclient.example.com.

上执行

谢谢

您评论中的错误和主机名表明您在错误的主机上使用了 apply 命令,即主机而不是远程客户端。

如果你想在不同的主机上执行命令,然后是 puppet-master(服务器),你需要在远程客户端上安装 puppet 代理,运行 在客户端上安装命令。即 sudo puppet agent -t 这将需要配置代理。

Puppet 使用来自 facter 的数据来确定节点名称。事实数据是根据实际主机名、/etc/hosts 以及 /etc/sysconfig/network 和其他信息填充的。您可以在 Puppets facter page.

上阅读更多相关信息

检查主机名的简单方法是 运行 hostname 命令或 facter hostnamefacter fqdn

下面是 Puppet 如何从 official website:

检查节点名称

A given node will only get the contents of one node definition, even if two node statements could match a node’s name. Puppet will do the following checks in order when deciding which definition to use:

If there is a node definition with the node’s exact name, Puppet will use it.

If there is a regular expression node statement that matches the node’s name, Puppet will use it. (If more than one regex node matches, Puppet will use one of them, with no guarantee as to which.) If the node’s name looks like a fully qualified domain name (i.e. multiple period-separated groups of letters, numbers, underscores and dashes), Puppet will chop off the final group and start again at step 1. (That is, if a definition for www01.example.com isn’t found, Puppet will look for a definition matching www01.example.) Puppet will use the default node.

Thus, for the node www01.example.com, Puppet would try the following, in order:

  • www01.example.com -- A regex that matches www01.example.com
  • www01.example -- A regex that matches www01.example
  • www01 -- A regex that matches www01
  • default

P.S。 如果您要降级,请提供理由。

命令puppet apply用于从本地清单文件和数据构建目录并将其应用到本地机器。您正在 运行 将其安装在您的主机上,并且您的站点清单不提供可以与该机器匹配的节点块,因此 Puppet 出错了。如果你想使用 puppet apply 那么你必须安排需要的清单和数据出现在你想要配置的机器上,你必须 运行 puppet apply .

如果你想使用master/agent配置,那么你必须运行某台指定机器上的master服务或puppetserver服务,所有清单和数据都必须驻留在那里。其他机器不需要清单或数据,它们通过 运行ning puppet agent(本地)而不是 puppet apply 配置自己。代理通常 运行 作为守护进程,但它也可以 运行 在一次性模式下,许多人使用它 运行 它在单独的调度程序的控制下,例如 cron.

显然,如果没有来自远程机器的某种形式的合作,您不能简单地通过 运行在主机上执行命令来配置远程机器——无论是与 Puppet 还是与您可能想象的任何其他系统。您也不希望您的机器容易受到这种不受限制的远程控制。

如果您正在寻找 真正的 遥控器,那么您可以考虑 Puppet 的 "MCollective" 产品。它需要机器的合作才能被控制,就像 Puppet 所做的那样,但它提供了 ad hoc 和按需控制,而 Puppet 没有做到这一点。除其他外,您还可以根据需要远程使用它 运行 puppet agent