如果我有一个正在创建的模板,我如何确保该目录存在?例如:
template "#{node[:app][:deploy_to]}/#{node[:app][:name]}/shared/config/database.yml" do
source 'database.yml.erb'
owner node[:user][:username]
group node[:user][:username]
mode 0644
variables({
:environment => node[:app][:environment],
:adapter => node[:database][:adapter],
:database => node[:database][:name],
:username => node[:database][:username],
:password => node[:database][:password],
:host => node[:database][:host]
})
end
Run Code Online (Sandbox Code Playgroud)
这失败了,因为/var/www/example/shared/config
不存在database.yml
要复制到。我在考虑 puppet 如何让您“确保”目录存在。
Tim*_*ter 19
在创建模板之前使用目录资源创建目录。诀窍是还要指定recursive
属性,否则除非目录的所有部分都已经存在,否则操作将失败。
config_dir = "#{node[:app][:deploy_to]}/#{node[:app][:name]}/shared/config"
directory config_dir do
owner node[:user][:username]
group node[:user][:username]
recursive true
end
template "#{config_dir}/database.yml" do
source "database.yml.erb"
...
end
Run Code Online (Sandbox Code Playgroud)
请注意,owner
和group
真实被创建时的目录资源的仅适用于叶目录。目录其余部分的权限未定义,但可能是 root.root 以及您的 umask 是什么。
归档时间: |
|
查看次数: |
27549 次 |
最近记录: |