为什么厨师食谱会跑两次?

时间:2017-07-19 15:39:50

标签: chef chef-recipe

我现在有一个非常基本的食谱。

include_recipe 'apache2'

Chef::Log.info(node[:inewebapp][:apache]);
node[:inewebapp][:apache].each do |vhost|
  Chef::Log.info("Currently on host #{vhost['docroot_dir']}");
end

我试图弄清楚 - 在用测试厨房构建这个 - 我是否收到了我的食谱多次运行的日志消息?

这是kitchen converge server

的输出
   Installing Cookbook Gems:
   Compiling Cookbooks...
   /tmp/kitchen/cache/cookbooks/hostsfile/resources/entry.rb:35: warning: constant ::Fixnum is deprecated
   [2017-07-19T15:36:05+00:00] INFO: [{"docroot_dir"=>"/var/www/host1", "server_name"=>"host1"}, {"docroot_dir"=>"/var/www/host2", "server_name"=>"host2"}]
   [2017-07-19T15:36:05+00:00] INFO: [{"docroot_dir"=>"/var/www/host1", "server_name"=>"host1"}, {"docroot_dir"=>"/var/www/host2", "server_name"=>"host2"}]
   [2017-07-19T15:36:05+00:00] INFO: Currently on host /var/www/host1
   [2017-07-19T15:36:05+00:00] INFO: Currently on host /var/www/host1
   [2017-07-19T15:36:05+00:00] INFO: Currently on host /var/www/host2
   [2017-07-19T15:36:05+00:00] INFO: Currently on host /var/www/host2

我没有attributes/default.rb文件为空,我的.kitchen.yml看起来像这样

  ---
  driver:
    name: vagrant

  provisioner:
    name: chef_zero
    product_name: chef
    product_version: 13.0.118
    log_level: info

  verifier:
    name: inspec

  platforms:
    - name: ubuntu-16.04

  suites:
    - name: server
      run_list:
        - recipe[apt]
        - recipe[ine-webapp::apache]
      verifier:
        inspec_tests:
          - test/integration/server
      attributes:
        inewebapp:
          user: 'vagrant'
          apache:
            - docroot_dir: /var/www/host1
              server_name: host1
            - docroot_dir: /var/www/host2
              server_name: host2

我知道我的食谱应该是幂等的,但我不确定为什么我的食谱被执行两次?

更新

在仔细检查我kitchen converge server的输出后,看起来正在运行chef-client的多个实例?还是不明白为什么呢?

       Transferring files to <server-ubuntu-1604>
   [2017-07-19T15:58:59+00:00] INFO: Started chef-zero at chefzero://localhost:8889 with repository at /tmp/kitchen, /tmp/kitchen
     One version per cookbook

   [2017-07-19T15:58:59+00:00] INFO: Started chef-zero at chefzero://localhost:8889 with repository at /tmp/kitchen, /tmp/kitchen
     One version per cookbook

   [2017-07-19T15:58:59+00:00] INFO: Forking chef instance to converge...
   [2017-07-19T15:58:59+00:00] INFO: Forking chef instance to converge...
   Starting Chef Client, version 13.0.118
   [2017-07-19T15:58:59+00:00] INFO: *** Chef 13.0.118 ***
   [2017-07-19T15:58:59+00:00] INFO: *** Chef 13.0.118 ***
   [2017-07-19T15:58:59+00:00] INFO: Platform: x86_64-linux
   [2017-07-19T15:58:59+00:00] INFO: Platform: x86_64-linux
   [2017-07-19T15:58:59+00:00] INFO: Chef-client pid: 14491
   [2017-07-19T15:58:59+00:00] INFO: Chef-client pid: 14491
   [2017-07-19T15:58:59+00:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
   [2017-07-19T15:58:59+00:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
   [2017-07-19T15:59:00+00:00] INFO: Setting the run_list to ["recipe[apt]", "recipe[ine-webapp::apache]"] from CLI options
   [2017-07-19T15:59:00+00:00] INFO: Setting the run_list to ["recipe[apt]", "recipe[ine-webapp::apache]"] from CLI options
   [2017-07-19T15:59:00+00:00] INFO: Run List is [recipe[apt], recipe[ine-webapp::apache]]
   [2017-07-19T15:59:00+00:00] INFO: Run List is [recipe[apt], recipe[ine-webapp::apache]]
   [2017-07-19T15:59:00+00:00] INFO: Run List expands to [apt, ine-webapp::apache]
   [2017-07-19T15:59:00+00:00] INFO: Run List expands to [apt, ine-webapp::apache]
   [2017-07-19T15:59:00+00:00] INFO: Starting Chef Run for server-ubuntu-1604
   [2017-07-19T15:59:00+00:00] INFO: Starting Chef Run for server-ubuntu-1604
   [2017-07-19T15:59:00+00:00] INFO: Running start handlers
   [2017-07-19T15:59:00+00:00] INFO: Running start handlers
   [2017-07-19T15:59:00+00:00] INFO: Start handlers complete.
   [2017-07-19T15:59:00+00:00] INFO: Start handlers complete.
   resolving cookbooks for run list: ["apt", "ine-webapp::apache"]

我的厨房清单中只有一个实例

    chef-repo/cookbooks/ine-webapp$ kitchen list
    Instance            Driver   Provisioner  Verifier  Transport  Last Action  Last Error
    server-ubuntu-1604  Vagrant  ChefZero     Inspec    Ssh        Converged    <None>

1 个答案:

答案 0 :(得分:0)

我们还不知道导致双重记录的原因,只是它看起来不够一致,无法调试:(如果你能提出一个最小的repro案例,请告诉我们。否则它似乎有时会离开。