Chef report in Foreman

Hello all,

A bit of context: I am using chef server (not managed by me and I can’t modify it) to setup all my new servers. For more visibility with my team I would like to use Foreman to get all the report from my chef-client. I don’t feel confident to run chef on production without control.

For that I installed foreman 1.18.2 in a server

foreman-installer
  --enable-foreman-plugin-chef
  --enable-foreman-plugin-tasks
  --enable-foreman-proxy-plugin-chef
  --foreman-proxy-plugin-chef-server-url="https://chef.server.company/organizations/companyname/"
  --foreman-proxy-plugin-chef-client-name="mycompany"
  --foreman-proxy-plugin-chef-private-key="/etc/chef/client.pem"
  --no-enable-puppet
  --foreman-server-ssl-crl=""

I also installed on my test client the gem chef_handler_foreman
/opt/chef/embedded/bin/gem install chef_handler_foreman --no-rdoc --no-ri

Chef-Client version Chef: 13.6.4

my client.rb /etc/chef/client.rb:

chef_server_url "https://chef.server.company/organizations/company/"
log_level :info
log_location :syslog
rubygems_url "https://gems.server.company"

# Do not crash if a handler is missing / not installed yet
begin
rescue NameError => e
  Chef::Log.error e
end

require 'chef_handler_foreman'
foreman_server_url 'https://foreman_server:8443'
foreman_facts_upload    true
foreman_reports_upload  true
reports_log_level       "notice"

When I restart my chef client I got a big error

Sep 14 07:54:18 test1.server.company chef-client[21612]: [2018-09-14T07:54:18+00:00] FATAL: Configuration error LoadError: cannot load such file -- chef_handler_foreman
Sep 14 07:54:18 test1.server.company chef-client[21612]: [2018-09-14T07:54:18+00:00] FATAL:   /etc/chef/client.rb:14:in `from_string'
Sep 14 07:54:18 test1.server.company chef-client[21612]: [2018-09-14T07:54:18+00:00] FATAL: Aborting due to error in '/etc/chef/client.rb'

I tried to look online but nothing help me to fix this issue. Any chance here?

Thanks a lot

Sorry Foreman server version 1.19.0

Found the issue

begin
 require 'chef_handler_foreman'
rescue LoadError
  Chef::Log.warn "Failed to load #{lib}. This should be resolved after a chef run."
end

foreman_server_options :url => 'https://foreman_server:8443'
foreman_facts_upload true
foreman_reports_upload true
foreman_enc true

Thanks for sharing. I never hit this, since my chef-client is bootstrapped by Foreman provisioning, that installs the gem. But I guess that works fine in your env.