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
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)
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\""