Foreman with puppet node.rb error 404 Not Found

2019-07-02 21:35发布

问题:

I have installed foreman-1.2 with puppet, after installation i have registered my puppet to smart-proxy on foreman.

when i run following command

[root@puppet ~]# puppet agent -t
Warning: Unable to fetch my node definition, but the agent run will continue:
Warning: Error 400 on SERVER: Failed to find puppet.example.com via exec: Execution of '/etc/puppet/node.rb puppet.example.com' returned 1: --- false

Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed when searching for node puppet.example.com: Failed to find puppet.example.com via exec: Execution of '/etc/puppet/node.rb puppet.example.com' returned 1: --- false

Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

I tried following

[root@puppet ~]# /etc/puppet/node.rb puppet.example.com
--- false
Error retrieving node puppet.example.com: Net::HTTPNotFound

foreman.log debug

Started GET "/node/puppet.example.com?format=yml" for 10.101.20.15 at 2014-03-25 21:01:47 -0400
Processing by HostsController#externalNodes as YML
  Parameters: {"name"=>"puppet.example.com"}
  Setting Load (1.3ms)  SELECT `settings`.* FROM `settings` WHERE `settings`.`name` = 'restrict_registered_puppetmasters' ORDER BY name LIMIT 1
  Setting Load (0.3ms)  SELECT `settings`.* FROM `settings` WHERE `settings`.`name` = 'require_ssl_puppetmasters' ORDER BY name LIMIT 1
  SmartProxy Load (0.5ms)  SELECT `smart_proxies`.* FROM `smart_proxies` INNER JOIN `features_smart_proxies` ON `features_smart_proxies`.`smart_proxy_id` = `smart_proxies`.`id` INNER JOIN `features` ON `features`.`id` = `features_smart_proxies`.`feature_id` WHERE `features`.`name` = 'Puppet' ORDER BY smart_proxies.name
  Setting Load (0.3ms)  SELECT `settings`.* FROM `settings` WHERE `settings`.`name` = 'trusted_puppetmaster_hosts' ORDER BY name LIMIT 1
Verifying request from ["puppet.example.com"] against ["puppet.example.com"]
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`login` = 'admin' LIMIT 1
Setting current user thread-local variable to admin
  Host::Managed Load (0.7ms)  SELECT `hosts`.* FROM `hosts` WHERE `hosts`.`type` IN ('Host::Managed') AND `hosts`.`certname` = 'puppet.example.com' LIMIT 1
  Host::Managed Load (0.6ms)  SELECT `hosts`.* FROM `hosts` WHERE `hosts`.`type` IN ('Host::Managed') AND `hosts`.`name` = 'puppet.example.com' LIMIT 1
Completed 404 Not Found in 25ms (ActiveRecord: 4.1ms)

Am i missing something? do i need to create host first on foreman GUI? I don't understand concept of node.rb

回答1:

First you should check the contents of node.rb. There are a number of variables that need to be set for it to work. It looks like this hasn't been done because the "Net::HTTPNotFound" says it can't find your Foreman server.

Second, yes and no -- the host needs to be defined in Froreman first. If the host doesn't exist in Foreman yet Foreman "may" create it -- it really depends on how you've set up Foreman.

If memory serves properly, I believe a non-existent host will be created when the facts are uploaded by node.rb (if that is enabled). If you're just running it from the command line, then no facts are being uploaded and the host isn't being created.

For your testing, ensure the host is created in Foreman. Then test node.rb (after you check that the vars in it are set properly).

EDIT: You're last question: node.rb's main function is to get the yaml formated config for a server and hand it to puppet. Secondary it also functions to upload facts from the server to Foreman -- which can be used in classifying the server in Foreman.



回答2:

Basically you have to make sure that the master and the agent are familiar with each other (either via /etc/hosts or dns). This error is usually raised when the master can not resolve the agent's name (e.g puppet.example.com)