ruby - Problems with chef recipe -
sorry english.
here ./recipes/default.rb
node['client-name'].each |crontab| item = data_bag_item('bag_name', "#{crontab}") node.default[:client_timezone] = "#{item['timezone']}" node.default[:client_name] = "#{crontab}" template "crontab" path "/etc/cron.d/#{deploy}" source "default.erb" owner "root" group "root" mode "0644" end end
the ./attributes/default.rb looks this:
default['version'] = "1.0.0" default['client-name'] = ['company_1','company_2']
the templates/crontab.erb
looks this:
30 04 * * * java -duser.timezone=<%= node[:timezone] %> -jar /var/www/app-<%= node[:version] %>.jar /var/www/<%= node[:client_name] %>/config/spring/job.xml
my recipe puts 2 similar crontab files (company_1 , company_2) /etc/cron.d/, last 1 attributes' value (company_2). can please tell me, wrong?
you need use variables section of template
resource assign client_name
, timezone
explicitly. recipe might this:
node['client-name'].each |client_name| item = data_bag_item('bag_name', "#{client_name}") template "crontab" path "/etc/cron.d/#{deploy}" source "default.erb" owner "root" group "root" mode "0644" variables ({ :client_name => item['client_name'], # don't have already? :client_timezone => item['client_timezone'] }) end end
your crontab.erb
should this:
30 04 * * * java -duser.timezone=<%= @client_timezone %> -jar /var/www/app-<%= node[:version] %>.jar /var/www/<%= @client_name %>/config/spring/job.xml
Comments
Post a Comment