I have the following code which downloads a file and then reads the contents of the file into a variable. Using that variable, it executes a command. This recipe will not converge because /root/foo does not exist during the compile phase.
I can workaround the issue with multiple converges and an
if File.exist
but I would like to do it with one converge. Any ideas on how to do it?
execute 'download_joiner' do
command "aws s3 cp s3://bucket/foo /root/foo"
not_if { ::File.exist?('/root/foo') }
end
password = ::File.read('/root/foo').chomp
execute 'join_domain' do
command "net ads join -U joiner%#{password}"
end
The correct solution is to use a lazy property:
execute 'download_joiner' do
command "aws s3 cp s3://bucket/foo /root/foo"
creates '/root/foo'
sensitive true
end
execute 'join_domain' do
command lazy {
password = IO.read('/root/foo').strip
"net ads join -U joiner%#{password}"
}
sensitive true
end
That delays the file read until after it is written. Also I included the sensitive
property so the password is not displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With