Reputation: 2641
In my recipe I have the following added:
directory '/opt/test/scripts' do
owner 'root'
group 'root'
mode '0755'
action :create
recursive true
not_if 'grep /opt/test'
end
uri=URI.parse('https://repo.test2.io/BwIaTHE0ohsUts74LYZMzrt/pair.sh')
response = Net::HTTP.get_response(uri)
File.write('/opt/test/scripts/pair.sh', response.body)
File = File.new( "/opt/test/scripts/pair.sh", "w" ).chmod( 0755 )
It looks strange, since it is trying to download the file and not create a directory where the file needs to be downloaded tooo.
It tries to download the file to the /opt directory and since the directory is not available it simply fails the execution process...
No such file or directory @ rb_sysopen - /opt/test/scripts/pair.sh
Is there a control mechanism that CHEF implements or is there a way to make CHEF understand the directory creation should happen first and then download??
Thank you
Upvotes: 0
Views: 351
Reputation: 54249
Chef uses a two-pass execution model detailed in https://coderanger.net/two-pass/ but basically first the Ruby code that is the recipe is run, which "compile" down to resources, and then the resources are evaluated. So putting a mix of resource DSL and plain Ruby in there means they do not execute in the order you expect (because the directory
resource was only queued up, not actually run). That said, what you want here is to use a remote_file
resource instead of your manual code, though in the more general case you can use a ruby_block
resource to delay running some code until converge time.
Upvotes: 1