【问题标题】:Chef BVT recipe needs to run only application deployment is performedChef BVT recipe 需要运行,仅执行应用程序部署
【发布时间】:2014-08-26 20:07:51
【问题描述】:

我已经预先准备了 BVT(自动化配方),它将作为每个厨师客户端的一部分在客户端服务器上运行,但我们需要修改它,BVT 配方只需要为应用程序部署触发,而不是其他配置更改。

请告诉我如何执行此操作

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

    我们遵循的方法是使用数据包在我们的部署配方中设置一个 deploy_allowed 标志和一个辅助方法,以测试是否允许部署。

    辅助方法看起来像(法语对不起):

    module Company
      def can_deploy?(bag, env, name)
        liv = data_bag_item(bag, env)
        msg = "Aucune entree trouvee, * ou #{name} pour l'environnement #{env}, deploiement refuse."
        liv_allowed = false
        entry = nil
    
        entry = '*' if liv.include?('*')
        entry = name if liv.include?(name)
    
        unless entry.nil?
          liv_allowed = true if liv[entry] == 'true'
          msg = "Deploiement #{liv_allowed ? 'autorise' : 'refuse'} par l'entree #{entry} de #{env}"
        end
        Chef::Log.info(msg)
        liv_allowed
      end
    end
    
    Chef::Recipe.send(:include, Company)
    Chef::Resource.send(:include, Company)
    Chef::Provider.send(:include, Company)
    

    Databag 项看起来像(在 json 中):

    {
      "id": "I1",
      "*": "false",
      "I1FR1WAS01": "true",
      "I1FR1WAS02": "false",
      "I1FR1WAS03": "false",
      "I1FR1WAS04": "false"
    }
    

    在食谱中,我们确实这样称呼它:

    if !can_deploy?("datab_bag",node.chef_environment,node.name) return
    

    在此示例中,节点的 chef_environment 为 I1,其名称为 I1R1WAS01,这允许它部署但不能部署其他服务器。

    我希望它可以帮助您适应您的需求。如果不清楚,请随时发表评论。

    【讨论】:

      猜你喜欢
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 2017-01-10
      • 2015-01-19
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      相关资源
      最近更新 更多