在提供者(方舟)之前执行的厨师模板

时间:2014-01-28 13:31:10

标签: chef

我正在开发一个使用ark提供程序的食谱和一些其他模板文件。

我的主要问题是模板文件是在执行ark之前创建的...因此执行配方时,文件所在的目录不存在。

如何在方舟完成后才能执行模板?

以下是食谱的代码:

version = node['tomcat']['version']
major_version = version[0]
download_url = "http://archive.apache.org/dist/tomcat/tomcat-#{major_version}/v#{version}/bin/apache-tomcat-#{version}.tar.gz"

user node['tomcat']['user'] do
    comment "Tomcat user"
    system true
    shell "/bin/false"
    home node['tomcat']['install_dir']
end

ark 'tomcat' do
    url download_url
    version version
    prefix_root node['tomcat']['install_dir']
    home_dir node['tomcat']['install_dir'] + "/tomcat"
    owner node['tomcat']['user']
end

template '/etc/init.d/tomcat' do
    source "tomcat.init.redhat.erb"
    owner "root"
    group "root"
    mode "0774"
    variables(:name => major_version)
end

service 'tomcat' do
  supports :restart => true, :reload => true, :status => true
  action [:enable, :start]
end

template node['tomcat']['install_dir'] + "/tomcat/conf/default" do
    source "default.erb"
    owner node['tomcat']['user']
    group node['tomcat']['user']
    mode "0644"
    variables(:tomcat => node['tomcat'].to_hash)
    notifies :restart, "service[tomcat]"
end

1 个答案:

答案 0 :(得分:1)

通知tomcat重新启动的方式相同。

ark 'tomcat' do
  # ...
  notifies :create, 'template[/etc/init.d/tomcat]', :immediately
end

然后确保将action :nothing添加到您的模板资源内联。