Search code examples
rubychef-infra

Read text file from web and assign to variable in Ruby / Chef


I'd like to read a text file from the web and assign it to a variable in chef / ruby

In powershell I would do something like this:

$content = (Invoke-WebRequest http://website.com/string.txt).content

Can anyone tell me how this is done in ruby?


Solution

  • Within Chef, the correct approach is to use the Chef::HTTP client.

    Chef::HTTP.new('https://example.com/').get('/string.txt')