Skip to main content

Chef: create a directory for a template if it doesn't already exist [Resolved]

If I have a template being created, how can I ensure that the directory exists? For instance:

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

This fails since /var/www/example/shared/config does not exist for database.yml to be copied into. I'm thinking of how puppet allows you to "ensure" a directory exists.


Question Credit: Matthew
Question Reference
Asked October 4, 2019
Posted Under: Network
21 views
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA