{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/7088","repository_url":"https://api.github.com/repos/chef/chef","labels_url":"https://api.github.com/repos/chef/chef/issues/7088/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/7088/comments","events_url":"https://api.github.com/repos/chef/chef/issues/7088/events","html_url":"https://github.com/chef/chef/issues/7088","id":309633879,"number":7088,"title":"Require inside of a client.d file does not work on first run","user":{"login":"martinisoft","id":724,"avatar_url":"https://avatars1.githubusercontent.com/u/724?v=4","gravatar_id":"","url":"https://api.github.com/users/martinisoft","html_url":"https://github.com/martinisoft","followers_url":"https://api.github.com/users/martinisoft/followers","following_url":"https://api.github.com/users/martinisoft/following{/other_user}","gists_url":"https://api.github.com/users/martinisoft/gists{/gist_id}","starred_url":"https://api.github.com/users/martinisoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinisoft/subscriptions","organizations_url":"https://api.github.com/users/martinisoft/orgs","repos_url":"https://api.github.com/users/martinisoft/repos","events_url":"https://api.github.com/users/martinisoft/events{/privacy}","received_events_url":"https://api.github.com/users/martinisoft/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-29T06:26:40Z","updated_at":"2018-04-01T17:51:03Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Description\r\n\r\nWhen you attempt to load a custom gem via the chef `client.d` folder in Chef Client (Chef Zero is also affected) it will not be available and raise an exception at the end of the run in which it is created and loaded. Subsequent runs will work normally.\r\n\r\n## Chef Version\r\n\r\nChef 12 and 13\r\n\r\n## Platform Version\r\n\r\nTested platforms:\r\nUbuntu 14.04 & 16.04\r\nCentOS 6 & 7\r\n\r\n## Replication Case\r\n\r\nI have created [a pull request](https://github.com/chef-cookbooks/chef-client/pull/567) which uses the example in the README (with corrections) in the test suite to demonstrate the problem. My hunch is that `Chef::Config[:client_d_dir]` for the chef_zero provisioner is going to `/tmp` and not loading the gem path to the newly installed gem via metadata.rb or the chef_gem directive. Somehow it's still being called at the end of the chef run.\r\n\r\n## Client Output\r\n\r\n```\r\nI, [2018-03-29T00:17:44.656488 #5478]  INFO -- default-ubuntu-1604: Running handlers:\r\nI, [2018-03-29T00:17:44.656630 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] INFO: Running report handlers\r\nI, [2018-03-29T00:17:44.656784 #5478]  INFO -- default-ubuntu-1604: Running handlers complete\r\nI, [2018-03-29T00:17:44.657008 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] INFO: Report handlers complete\r\nI, [2018-03-29T00:17:44.657148 #5478]  INFO -- default-ubuntu-1604: Chef Client finished, 88/140 resources updated in 02 minutes 03 seconds\r\nI, [2018-03-29T00:17:44.657290 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] DEBUG: Server doesn't support resource history, skipping resource report.\r\nI, [2018-03-29T00:17:44.657439 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] DEBUG: Audit Reports are disabled. Skipping sending reports.\r\nI, [2018-03-29T00:17:44.657576 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] DEBUG: Forked instance successfully reaped (pid: 1562)\r\nI, [2018-03-29T00:17:44.657719 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL: Configuration error LoadError: cannot load such file -- bugsnag\r\nI, [2018-03-29T00:17:44.657899 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL:   /tmp/kitchen/client.d/bugsnag.rb:1:in `from_string'\r\nI, [2018-03-29T00:17:44.658042 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL: Aborting due to error in '/tmp/kitchen/client.d/bugsnag.rb'\r\n```\r\n\r\n## Stacktrace\r\n\r\n```\r\nI, [2018-03-29T00:17:44.657719 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL: Configuration error LoadError: cannot load such file -- bugsnag\r\nI, [2018-03-29T00:17:44.657899 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL:   /tmp/kitchen/client.d/bugsnag.rb:1:in `from_string'\r\nI, [2018-03-29T00:17:44.658042 #5478]  INFO -- default-ubuntu-1604: [2018-03-29T05:17:42+00:00] FATAL: Aborting due to error in '/tmp/kitchen/client.d/bugsnag.rb'\r\n```\r\n\r\n## Workaround\r\n\r\nFor the time being, I have wrapped the requires in rescue blocks like so:\r\n\r\n```ruby\r\nbegin\r\n  require 'bugsnag'\r\n  Bugsnag.configure do |config|\r\n    config.api_key = '1234567890'\r\n  end\r\nrescue LoadError\r\n  Chef::Log.warn('Could not load bugsnag gem. If this is the first run, it will resolve itself. If not, then something has gone horribly wrong.')\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/377804271","html_url":"https://github.com/chef/chef/issues/7088#issuecomment-377804271","issue_url":"https://api.github.com/repos/chef/chef/issues/7088","id":377804271,"user":{"login":"lamont-granquist","id":454857,"avatar_url":"https://avatars0.githubusercontent.com/u/454857?v=4","gravatar_id":"","url":"https://api.github.com/users/lamont-granquist","html_url":"https://github.com/lamont-granquist","followers_url":"https://api.github.com/users/lamont-granquist/followers","following_url":"https://api.github.com/users/lamont-granquist/following{/other_user}","gists_url":"https://api.github.com/users/lamont-granquist/gists{/gist_id}","starred_url":"https://api.github.com/users/lamont-granquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamont-granquist/subscriptions","organizations_url":"https://api.github.com/users/lamont-granquist/orgs","repos_url":"https://api.github.com/users/lamont-granquist/repos","events_url":"https://api.github.com/users/lamont-granquist/events{/privacy}","received_events_url":"https://api.github.com/users/lamont-granquist/received_events","type":"User","site_admin":false},"created_at":"2018-04-01T17:51:03Z","updated_at":"2018-04-01T17:51:03Z","author_association":"CONTRIBUTOR","body":"So earlier in the run you've successfully done `chef_gem \"bugsnag\"` or installed it via metadata.rb then?\r\n\r\nOffhand, I can only be puzzled.  It smells like bundler, but we don't bundle inside of TK AFAIK, and AFAIK we don't do anything weird with rubygems in report handlers, and would probably look more in the direction of the rubygems package resource behaving strangely.  If its a regression it might be due to the recent patch there to work around the embedded-gems problem."}}
{"actor":{"display_login":"lamont-granquist"}}