0

I have a recipe that updates the Splunk /opt/splunkforwarder/etc/system/local/inputs.conf file with single entry for meta data that needs to be added to the events that are being forwarded to the indexers.

This meta data entry is a nine character text entry in a configuration file of another piece of software that has already been installed on the host.

I have the code to read the data from this file but when it comes to running test-kitchen I don't know how to declare where the test file that has this information is located in my .kitchen.yml file.

I've tried creating a directory at the root of my repo with this file in it thinking it would be copied over like the roles, environments, cookbook directories are so my .kitchen.yml contained an entry:

    attributes: 
      splunk:
        sliceconf_path: test/slice.conf

However I would get an error like

Errno::ENOENT
       -------------
       No such file or directory @ rb_sysopen - test/slice.conf

I've tried many other locations but I still can't get it to find this file. It will get copied over if I put it in "files/test/slice.conf" but then it still can't find it if I declare the path either

sliceconf_path: files/test/slice.conf

or (based on examining the directory structure of the Docker image I'm using for Test-Kitchen)

cookbooks/cookbook-dh_rainbow_forwarders/files/test/slice.conf

I'm stumped as to how to get Chef/Test-Kitchen to find the file.

----------------EDIT-------------------

Here's the code I'm using just to clarify:

Recipe
slice_name = ''
ruby_block 'read_slice_conf' do
  block do
    slice_name = File.read("#{node['sliceconf_path']}").chomp
  end
end

# Update local input conf file with meta-data about slice.
 template '/opt/splunkforwarder/etc/system/local/inputs.conf' do
   source 'system_local_inputs.erb'
   owner 'nobody'
   group 'nobody'
  mode 0o600
  mode '0600'
   action :create
  variables(
    slice_decorators: slice_name
  )
 end

Template
[default]
host = <%= node['fqdn'] %>

_meta = slice::#{slice_name}

Where I've set the node attribute (node['sliceconf_path']) in my .kitchen.yml

user3481957
  • 151
  • 1
  • 1
  • 10

1 Answers1

0

It sounds like you are doing something like IO.read(node['splunk']['sliceconf_path']), meaning it has to be an absolute path on the target VM, it would have no knowledge of Chef-y things like you are giving it. But That attribute doesn't exist in the community splunk cookbook so I can't tell how the code works. If you want it to automatically understand cookbook_files, you'll need to write the code for that.

coderanger
  • 52,400
  • 4
  • 52
  • 75