Chef-splunk-windows and chef-vault getting error while installing


#1

Hi,

I am trying to install Splunk Universal forwarder using chef-splunk-windows cookbook. I am getting the below error while trying to do that.

================================================================================←[0m
←[31mRecipe Compile Error in c:/chef/cache/cookbooks/chef-splunk-windows/recipes/default.rb←[0m
================================================================================←[0m

←[0mNet::HTTPServerException←[0m
------------------------←[0m
404 "Object Not Found"←[0m

←[0mCookbook Trace:←[0m
---------------←[0m
  c:/chef/cache/cookbooks/chef-vault/libraries/helpers.rb:38:in `chef_vault_item'
←[0m  c:/chef/cache/cookbooks/chef-splunk-windows/recipes/setup_auth.rb:22:in `from_file'
←[0m  c:/chef/cache/cookbooks/chef-splunk-windows/recipes/client.rb:45:in `from_file'
←[0m  c:/chef/cache/cookbooks/chef-splunk-windows/recipes/default.rb:26:in `from_file'←[0m

←[0mRelevant File Content:←[0m
----------------------←[0m
c:/chef/cache/cookbooks/chef-vault/libraries/helpers.rb:
←[0m
←[0m 31:    # +node['chef-vault']['databag_fallback']+.
←[0m 32:    # @example
←[0m 33:    # item = chef_vault_item('secrets', 'bacon')
←[0m 34:    # log 'Yeah buddy!' if item['_default']['type']
←[0m 35:    # @param [String] bag Name of the data bag to load from.
←[0m 36:    # @param [String] id Identifier of the data bag item to load.
←[0m 37:    def chef_vault_item(bag, id)
←[0m 38>>     if ChefVault::Item.vault?(bag, id)
←[0m 39:        chef_vault_item(bag, id)
←[0m 40:         # ChefVault::Item.load(bag, id)
←[0m 41:      elsif node['chef-vault']['databag_fallback']
←[0m 42:        data_bag_item(bag, id)
←[0m 43:      else
←[0m 44:        raise "Trying to load a regular data bag item #{id} from #{bag}, and databag_fallback is disabled"
←[0m 45:      end
←[0m 46:    end
←[0m 47:
←[0m
←[0mSystem Info:←[0m

Please help me.


#2

We gave up on the splunk cookbook for windows because it was overly complex.

You can install splunk universal forwarder with chocolatey

choco install spunkforwarder --version 6.5.1 --params="RECEIVING_INDEXER=foobar.example.com:8089"

Or if you use a deployment server instead of a receiving indexer

choco install spunkforwarder --version 6.5.1 --params="DEPLOYMENT_SERVER=foobar.example.com:8089"

It is trivial to convert those commands into a chef resource in your own cookbook

chocolatey_package 'splunkforwarder' do
  version 6.5.1
  options "--params=\"DEPLOYMENT_SERVER=#{node['foobar-splunk-uf']['deployment_server']}\""
end

If you need to support both universal forwarder installation types (receiving indexer and deployment server, your recipe will be a little more complicated, but still relativly simple)

if !node['nd-splunk-uf']['receiving_indexer'].nil? && !node['nd-splunk-uf']['deployment_server'].nil?
  raise "Set either receiving_indexer or deployment_server, not both"
end

chocolatey_package 'splunkforwarder' do
  version 6.5.1
  options "--params=\"RECEIVING_INDEXER=#{node['foobar-splunk-uf']['receiving_indexer']}\"" if node['foobar-splunk-uf']['receiving_indexer']
  options "--params=\"DEPLOYMENT_SERVER=#{node['foobar-splunk-uf']['deployment_server']}\"" if node['foobar-splunk-uf']['deployment_server']
  action :install
end

#3

Hi Spuder,

Thank you for your reply.
I have tried your code to install Splunk forwarder but there is an issue. find the screen shot.

I have tried the below code:

chocolatey_package 'splunkforwarder' do
version 6.5.1
options "--params=\"RECEIVING_INDEXER=#{node['localhost:9997']['receiving_indexer']}\""
 end

I used the chocolaty URL:

source https://chocolatey.org/api/v2/package/splunkforwarder/6.5.1

Still no use.

Thank you.


#4

Change the version 6.5.1 to a string. ‘6.5.1’


#5

Hi spuder,

I want to thank you for your efforts. I have changed it to string. But now i got another error. below is the stacktrace.out filr.

Generated at 2017-08-02 16:39:00 +0000
NoMethodError: undefined method `[]' for nil:NilClass
default.rb:9:in `block in run_chef_recipe'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/resource_builder.rb:66:in `instance_eval'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/resource_builder.rb:66:in `build'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/dsl/declare_resource.rb:293:in `build_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/dsl/declare_resource.rb:250:in `declare_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/dsl/resources.rb:38:in `chocolatey_package'
default.rb:7:in `run_chef_recipe'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/application/apply.rb:192:in `instance_eval'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/application/apply.rb:192:in `run_chef_recipe'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/application/apply.rb:204:in `run_application'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/application/apply.rb:216:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/bin/chef-apply:25:in `<top (required)>'
C:/opscode/chefdk/modules/chef/../../bin/chef-apply:275:in `load'
C:/opscode/chefdk/modules/chef/../../bin/chef-apply:275:in `<main>'

Also the error screen.

Thank you.


#6

Chef-apply doesn’t work like a normal chef run. While some things will work the same, a lot of things wont. If possible, test this with chef-zero or test kitchen.

The error undefined method for nil class means that there is an undefined variable. In this case, there is no such variable #{node['localhost:9997']['receiving_indexer']}. I think you are mixing up how to do variables(aka attributes) in chef. For a proof of concept, try hard coding it.

If you are hard coding the indexer, the resource would look like this

chocolatey_package 'splunkforwarder' do
  version 6.5.1
  options "--params=\"RECEIVING_INDEXER=localhost:9997\""
end

If you are using an attribute(variable), you would define that in the role, environment, policyfile, cookbook default attributes or .kitchen.yaml file (depending on your deployment strategy)

default['foobar-splunk-uf']['receiving_indexer'] = 'localhost:9997'

chocolatey_package 'splunkforwarder' do
  version 6.5.1
  options "--params=\"RECEIVING_INDEXER=#{node['foobar-splunk-uf']['receiving_indexer']}\""
end

#7

i have hardcoded that but ,

Do we need to install any chocolaty cookbook before this? am i missing something? Please help me out.

←[0m    Chef::Exceptions::MissingLibrary←[0m
    --------------------------------←[0m
    Could not locate your Chocolatey install. To install chocolatey, we recommend
←[0m    the 'chocolatey' cookbook (https://github.com/chocolatey/chocolatey-cookbook).
←[0m    If Chocolatey is installed, ensure that the 'ChocolateyInstall' environment
←[0m    variable is correctly set. You can verify this with the PowerShell command
←[0m    '[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')'.
←[0m
←[0m    Resource Declaration:←[0m
    ---------------------←[0m
    # In default.rb
←[0m
←[0m      7: chocolatey_package 'splunkforwarder' do
←[0m      8:   version '6.5.1'
←[0m      9:   options "--params=\"RECEIVING_INDEXER=localhost:9997\""
←[0m     10: end←[0m

←[0m    Compiled Resource:←[0m
    ------------------←[0m
    # Declared in default.rb:7:in `run_chef_recipe'
←[0m
←[0m    chocolatey_package("splunkforwarder") do
←[0m      package_name ["splunkforwarder"]
←[0m      action [:install]
←[0m      default_guard_interpreter :default
←[0m      declared_type :chocolatey_package
←[0m      cookbook_name "(chef-apply cookbook)"
←[0m      recipe_name "(chef-apply recipe)"
←[0m      version ["6.5.1"]
←[0m      options "--params=\"RECEIVING_INDEXER=localhost:9997\""

Can you please make me clear about this.


#8

You don’t have chocolatey installed. Chocolatey doesn’t come by default on windows images. Check out chocolatey.org

You can install chocolatey in your golden image with packer, or use the chocolatey cookbook to install chocolatey.


#9

Thank you spuder… I appreciate your efforts. It seems i have installed uf.

:slightly_smiling_face: