【问题标题】:Problems with chef recipe厨师食谱的问题
【发布时间】:2014-08-19 00:43:17
【问题描述】:

对不起我的英语。

这是一个 ./recipes/default.rb

node['client-name'].each do |crontab|   
    item = data_bag_item('bag_name', "#{crontab}")

    node.default[:client_timezone] = "#{item['timezone']}"
    node.default[:client_name] = "#{crontab}"

    template "crontab" do
        path "/etc/cron.d/#{deploy}"
        source "default.erb"
        owner "root"
        group "root"
        mode "0644"
    end
end

./attributes/default.rb 看起来像这样:

default['version'] = "1.0.0"
default['client-name'] = ['company_1','company_2']

templates/crontab.erb 看起来像这样:

30 04 * * * java -Duser.timezone=<%= node[:timezone] %> -jar /var/www/app-<%= node[:version] %>.jar /var/www/<%= node[:client_name] %>/config/spring/job.xml

我的食谱将两个相似的 crontab 文件(company_1 和 company_2)放入 /etc/cron.d/,但仅用于最后一个属性的值(company_2)。你能告诉我,我哪里错了吗?

【问题讨论】:

  • crontab.erb 看起来怎么样?
  • 30 04 * * * java -Duser.timezone= -jar /var/www/app-.jar /var/www//config/spring/job.xml

标签: ruby arrays attributes chef-infra


【解决方案1】:

您需要使用template 资源的变量部分来明确分配client_nametimezone。配方可能如下所示:

node['client-name'].each do |client_name|   
    item = data_bag_item('bag_name', "#{client_name}")

    template "crontab" do
        path "/etc/cron.d/#{deploy}"
        source "default.erb"
        owner "root"
        group "root"
        mode "0644"
        variables ({
            :client_name => item['client_name'], # Don't you have this already?
            :client_timezone => item['client_timezone']
        })
    end
end

您的crontab.erb 应如下所示:

30 04 * * * java -Duser.timezone=<%= @client_timezone %> -jar /var/www/app-<%= node[:version] %>.jar /var/www/<%= @client_name %>/config/spring/job.xml

【讨论】:

  • 谢谢,伙计,这正是我所需要的。我是厨师和红宝石的新手,所以我的问题可能有点迟钝..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 2019-01-29
  • 2014-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多