Last active
May 19, 2022 12:21
-
-
Save christinedraper/334b45edb8e52f4e9dfe to your computer and use it in GitHub Desktop.
Chef derived attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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