0

We're trying to install New Relic infrastructure agent using a third party cookbook. But we've got an error:
Error executing action install on resource 'newrelic_agent_infrastructure[Install]'

Our Recipe:

#
# Cookbook:: third-party-newrelic
# Recipe:: infraestructure-agent
#
# Copyright:: 2018, The Authors, All Rights Reserved.

include_recipe 'base::databag'
include_recipe 'newrelic::infrastructure_agent'
# Default Variables
newrelic = decrypt_databag('newrelic')

node.normal['newrelic']['license'] = newrelic['license_key']

Log Error:

Recipe: newrelic::infrastructure_agent
  * newrelic_agent_infrastructure[Install] action install

    ================================================================================
    Error executing action `install` on resource 'newrelic_agent_infrastructure[Install]'
    ================================================================================

    RuntimeError
    ------------
    The NewRelic key is required.

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/newrelic/libraries/helpers.rb:15:in `check_license'
    /var/chef/cache/cookbooks/newrelic/providers/agent_infrastructure.rb:18:in `block in class_from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/newrelic/recipes/infrastructure_agent.rb

      8: newrelic_agent_infrastructure 'Install'

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/newrelic/recipes/infrastructure_agent.rb:8:in `from_file'

    newrelic_agent_infrastructure("Install") do
      action [:install]
      default_guard_interpreter :default
      declared_type :newrelic_agent_infrastructure
      cookbook_name "newrelic"
      recipe_name "infrastructure_agent"
    end

    System Info:
    ------------
    chef_version=13.8.5
    platform=ubuntu
    platform_version=16.04
    ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
    program_name=chef-client worker: ppid=101819;start=19:52:27;
    executable=/opt/chef/bin/chef-client


Running handlers:
[2018-05-10T19:52:34+00:00] ERROR: Running exception handlers
Running handlers complete
[2018-05-10T19:52:34+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 07 seconds
[2018-05-10T19:52:34+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2018-05-10T19:52:34+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-05-10T19:52:34+00:00] ERROR: newrelic_agent_infrastructure[Install] (newrelic::infrastructure_agent line 8) had an error: RuntimeError: The NewRelic key is required.
[2018-05-10T19:52:34+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Even though using the follow line instead of a data bag:

node.default_unless['newrelic']['license'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

We've tried many alternatives for this command, but it wasn't fertile.

Thanks in Advance.

2 Answers 2

1

Is the relevant code so that should work, but you can try:

node.override['newrelic']['application_monitoring']['license'] = 'asdf'
5
  • Are you sure you are setting the attribute in a place before it would get used?
    – coderanger
    May 11, 2018 at 18:50
  • 2
    Oh hey, yep, bug in the cookbook github.com/djoos-cookbooks/newrelic/blob/master/resources/…
    – coderanger
    May 11, 2018 at 18:51
  • It doesn't have the lazy{} wrapper so that's getting evaluated at file compile time. You would have to set the attr via a role or environment or something else static.
    – coderanger
    May 11, 2018 at 18:52
  • Thanks a lot @coderanger, I saw that you have opened an Issue for djoos to correct the wrapper. ". You would have to set the attr via a role or environment or something else static." We thought about it, but how can we manager to insert a data bag in a role? Thanks in advance.
    – Daniel
    May 11, 2018 at 19:45
  • 1
    You unfortunately cannot use a data bag at this time.
    – coderanger
    May 11, 2018 at 21:50
0

by the issue: https://github.com/djoos-cookbooks/newrelic/issues/345

Ok. We manage to solve this problem by changing this line in the followed files: ../resources/agent_infrastructure.rb ../resources/agent_php.rb

From:

attribute :license, :kind_of => String, :default => NewRelic.application_monitoring_license(node)

To:

attribute :license, :kind_of => String, :default => lazy { NewRelic.application_monitoring_license(node) }

Inside the recipe

node.default['newrelic']['license'] = newrelic['license_key']

Calling our data bag with this structure:

id: newrelic

license_key:xxxxxxxxxxxxxxxxxxxxx

Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.