Edit: complete rewrite due to down-voting but without more information I'm not sure what exactly I'm correcting so here is working code that can be copied and pasted.
Assuming contents of properties file placed in /tmp/versions.properties and looks like the following:
apache=2.4.7-1ubuntu4.8
php=5.4.3
sendmail=1.2.3
Chef Cook book
# Copy a file with versions
cookbook_file '/tmp/versions.properties' do
source 'versions.properties'
mode '0644'
end
# Setvar
node.default['version'] = ""
# Block where we set the command
ruby_block "set_app_id" do
block do
node.set['version'] = "apt-get install apache2=`grep -o 'apache=.*' /tmp/versions.properties | cut -f2- -d'='`"
end
action :create
end
# Do a lazy install
execute "install lazy based" do
command lazy {node[:version]}
end
As a bonus option if you are working strictly on *nix the following works without lazy:
# Execute straight up
execute "install lazy based" do
command "apt-get install apache2=`grep -o 'apache=.*' /tmp/versions.properties | cut -f2- -d'='`"
end
I still used the original premise of the links in the first two posts referenced:
Assuming that properties file is on the server(?) you could use lazy
evaluation as described [in this post][1]
Edit: Check this [one out too][2]
[1]:
https://stackoverflow.com/questions/26238056/setting-chef-variable-via-a-ruby-block-not-being-executed.
[2]:
https://stackoverflow.com/questions/20620724/how-to-lazily-evaluate-an-arbitrary-variable-with-chef