I have an issue when using variables in recipes.
I created a custom resource, which i use from a recipe. Within the recipe i have defined a variable. The custom resource has a property which has the same name as the variable. This seems to give a conflict.
How can i prevent that, when using variables the conflict with a resource? As i do not know all possible properties this can always happen (i assume).
resource_name :minimal
property :name, String, name_property: true
property :libj, [Array, String], required: true
action :install do
# TODO: CLEANUP
# TODO: check if libj property works as intended.
sid = node['logcollector']['sid'].upcase
sid_d = sid.downcase
sidadm = "#{sid_d}adm"
rlibj = [*new_resource.libj]
adapterpath = "/hana/shared/#{sid}/streaming/cluster/#{sid_d}/adapters"
rlibj.each do |l|
print "#{l}\n"
end
end
libj = 'This collides with libj in minimal resource'
minimal 'rtparseradapter' do
libj [
'https://docs.chef.io/_static/chef_logo_v2.svg',
'https://docs.chef.io/_static/LearnChefRally_300x250_v01.1b.jpg',
'https://docs.chef.io/_static/usability_testing%20_banner_300x250.png'
]
action :install
notifies :restart, 'etdproject[proxy_tle]', :immediately
end
etdproject 'proxy_tle' do
action :nothing
end
ArgumentError
-------------
wrong number of arguments (given 3, expected 1..2)
Cookbook Trace:
---------------
/etc/chef/local-mode-cache/cache/cookbooks/ETD-LogCollector/recipes/minimal.rb:11:in `[]'
/etc/chef/local-mode-cache/cache/cookbooks/ETD-LogCollector/recipes/minimal.rb:11:in `block in from_file'
/etc/chef/local-mode-cache/cache/cookbooks/ETD-LogCollector/recipes/minimal.rb:10:in `from_file'
Relevant File Content:
----------------------
/etc/chef/local-mode-cache/cache/cookbooks/ETD-LogCollector/recipes/minimal.rb:
4: #
5: # Copyright:: 2018, The Authors, All Rights Reserved.
6: #
7:
8: libj = 'This collides with libj in minimal resource'
9:
10: minimal 'rtparseradapter' do
11>> libj [
12: 'https://docs.chef.io/_static/chef_logo_v2.svg',
13: 'https://docs.chef.io/_static/LearnChefRally_300x250_v01.1b.jpg',
14: 'https://docs.chef.io/_static/usability_testing%20_banner_300x250.png'
15: ]
16: action :install
17: notifies :restart, 'etdproject[proxy_tle]', :immediately
18: end
19:
20: etdproject 'proxy_tle' do