- From: Sean OMeara <
>
- To: "
" <
>
- Subject: [chef] Re: [CHEF]Create random file and assign to a variable in recipe
- Date: Thu, 23 Jul 2015 09:38:10 -0400
This one is tricky...
You'll need to calculate your string(s) during the compilation phase or your recipe, and pass then use them in your resources. Something like this.
my_string = 'ABC123etcetc'
directory "/stuff/#{my_string}" do
action :create
end
file "/stuff/#{my_string}/file_1" do
action :create
end
file "/stuff/#{my_string}/file_2" do
action :create
end
However, you need need to be careful how you generate my_string.
You'll be tempted to make them actually random
require 'securerandom'
my_string = SecureRandom.hex
This won't work, because my_string will change on subsequent chef-client runs.
You'll need to use something like:
require 'digest'
seed = "constant"
my_string = Digest::SHA1.hexdigest(seed)[0,8]
Hope that helps.
-s
Archive powered by MHonArc 2.6.16.