【问题标题】:Example Chef HTTP GET/POST Cookbook示例 Chef HTTP GET/POST 食谱
【发布时间】:2015-03-12 11:58:32
【问题描述】:

我正在学习厨师,需要一个非常简单的准系统食谱/食谱示例,它可以调用外部 HTTP API (GET/POST) 并将内容放入文件中。我浏览了社区食谱,但它们似乎对于学习和试图了解正在发生的事情来说都是多余的,而且自然大多数似乎都专注于安装软件包。有没有人有我可以在这里使用的东西:)

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

    您可以根据需要使用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

    【讨论】:

      【解决方案2】:

      一种简单的方法是使用 ruby​​ 中的“net/http”模块在 ruby​​_block 中发送请求并处理响应。有关模式信息,请参阅:http://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html

      【讨论】:

        猜你喜欢
        • 2014-11-06
        • 1970-01-01
        • 1970-01-01
        • 2015-10-24
        • 2015-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多