我正在学习厨师,需要一个非常简单的简单的食谱/食谱示例,可以调用外部HTTP API (GET/POST)并将内容放入文件中。我看过社区的食谱,但它们似乎都是在学习和试图理解发生了什么,自然地,大多数似乎集中在安装包上。有没有什么我可以在这里用到的:)
发布于 2015-03-04 23:48:52
您可以根据需要使用remote_file
资源,例如:
remote_file "/tmp/testfile" do
source "http://www.example.com/tempfiles/testfile"
mode '0644'
checksum "3a7dac00b1" # A SHA256 (or portion thereof) of the file.
end
您可以在nginx community cookbook中看到它的实际效果
nginx_url = node['nginx']['source']['url'] ||
"http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"
src_filepath = "#{Chef::Config['file_cache_path'] || '/tmp'}/nginx-#{node['nginx']['source']['version']}.tar.gz"
....
remote_file nginx_url do
source nginx_url
checksum node['nginx']['source']['checksum']
path src_filepath
backup false
end
关于这个内置资源的更多信息,你可以通过find here获取。
发布于 2015-03-12 11:58:32
一种简单的方法是使用ruby .For模式中的“net/http”模块在ruby_block中发送请求和处理响应。有关信息,请参阅:http://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html
https://stackoverflow.com/questions/28856715
复制相似问题