Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chef derived attribute
default["app"]["name"] = "app"
# Attribute to show the problem
default["app"]["install_dir"] = "/home/#{node["app"]["name"]}"
# Attribute used in delayed evaluation approach
default["app"]["install_dir2"] = "/home/%{name}"
# Attribute used in conditional assignment approach
# default["app"]["install_dir3"] = "/home/#{node["app"]["name"]}"
#
# Cookbook Name::app
# Recipe:: conditional
#
install_dir = node['app']['install_dir3'] || "/var/#{node['app']['name']}"
# Alternative to line above that will set the node attribute
#node.default['app']['install_dir3'] = "/var/#{node['app']['name']}" unless node['app']['install_dir3']
#install_dir = node['app']['install_dir3']
ruby_block "Executing resource in recipe" do
block do
Log.info "Executing recipe, application name is: #{node['app']['name'] };" +
" install_dir is #{install_dir}"
end
end
#
# Cookbook Name:: app
# Recipe:: default
#
ruby_block "Executing resource in recipe" do
block do
Log.info "Executing recipe, application name is: #{node['app']['name'] };" +
" install_dir is #{node['app']['install_dir']}"
end
end
#
# Cookbook Name:: app
# Recipe:: delayed
#
install_dir = node['app']['install_dir2'] % { name: node['app']['name'] }
ruby_block "Executing resource in recipe" do
block do
Log.info "Executing recipe, application name is: #{node['app']['name'] };" +
" install_dir is #{install_dir}"
end
end
default["app"]["name"] = "my_app"
# Uncomment these to test that the install_dir can be overridden
# default["app"]["install_dir"] = "/tmp"
# default["app"]["install_dir2"] = "/tmp"
# default["app"]["install_dir3"] = "/tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.