【问题标题】:Puppet Nodes.pp Include Modules Execution OrderPuppet Nodes.pp 包含模块执行顺序
【发布时间】:2012-10-10 18:50:00
【问题描述】:

我正在尝试在我的某些模块上为某些节点设置顺序。

node basenode{
 include ps
 include netfx
 include hg
 include reportviewer2012
 include wdeploy30
 include sqlexpress2008
 include windowsrolesfeatures
 include tcbase
}

node 'myserver' inherits basenode  {
 include tcuiagent

 Class['tcuiagent'] -> Class['tcbase'] -> Class['windowsrolesfeatures'] -> Class['ps']
}

当然,我不想在模块资源中设置依赖关系,因为这会使它们相互依赖,而我不想这样做。在这种情况下,我想完成这个命令。

  1. ps(第一个)
  2. windows 角色功能
  3. anyotherpackage {hg,netfx...}(不关心配置顺序) n. tcbase
  4. tcuigant(最后一个)

【问题讨论】:

    标签: provisioning puppet


    【解决方案1】:

    如果你真的不想表达模块之间的关系,你可以使用阶段来强制执行顺序。

    您必须首先在顶级清单中声明阶段:

    ## Very important : we define stages.
    ## Can only be done here.
    stage { 'first': }      # the first of first
    stage { 'apt': }        # to install apt sources and run apt-get update if necessary
    # stage main            # default stage, always available
    stage { 'last': }       # a stage after all the others
    # Now we define the order :
    Stage[first] -> Stage[apt] -> Stage[main] -> Stage[last]
    

    然后使用它们:

    # basics needing a run state
    # We use the "class" syntax here because we need to specify a run stage.
    class
    {
       'puppeted': # debug
          stage   => first, # note the explicit stage !
          ;
       'apt_powered': # Very important for managing apt sources
          stage   => apt, # note the explicit stage !
          #offline => 'true', # uncomment this if you are offline or don't want updates
          ;
       'apt_powered::upgraded': # will systematically upgrade paquets. dev machine -> we want to stay up to date
          stage   => apt, # note the explicit stage !
          ;
    }
    

    但这很丑陋,这不是舞台的目的。

    【讨论】:

    • 我想我别无选择。 1.创建资源之间的关系,即使它们属于不同的模块。示例(netfx40、netfx45、sql2012)。在这种情况下,我有三个模块,但依赖链是声明为 sql2012->netfx45->netfx40。猜测您不能在没有其他模块的情况下重新分发 sql2012 模块。 2.通过使用阶段,我在顶层创建关系,但资源不再独立,因为它们有一个需要在 site.pp 设置的变量“阶段”
    【解决方案2】:

    我强烈建议重写模块,以便它们的安装顺序不再重要,或者创建与资源的必要关系。

    如果您要安装/配置来自不同模块的相关资源,您可以考虑合并这些模块。

    德国。

    【讨论】:

    • 如果我在资源之间创建关系,那么您就是在使来自不同模块的资源相互依赖,我确实想在顶层创建这种关系,但使用阶段看起来真的很难看。
    • 好名字!我想象一头树熊将苹果扔在一个毫无戒心的野餐者身上。
    【解决方案3】:

    我想我使用不同的节点继承方法来解决它。

    node windowsmachine{
     include ps #powershell 
     include windowsrolesfeatures #windows roles and features
     include netfx #netframework 4.0 and 4.5
    }
    
    node teamcitybase inherits windowsmachine {
     include hg #mercurial
     include nuget #nuget configuration
     include reportviewer2012 
     include wdeploy30 #web deployment 3.0
     include tcbase #asp.net configuration
     include sqlexpress2008 #sqlexpress
    }
    
    node 'myserver1','myserver2' inherits teamcitybase{
     #pending installation of puppet clients
    }
    
    node 'myserver3' inherits teamcitybase  {
     include tcuiagent 
    }
    

    Windows 机器配置模块不相互依赖,但带有 sqlexpress2008 的 myserver1 依赖于该基线。

    没有阶段或模块依赖!!!!!

    【讨论】:

      【解决方案4】:

      在发布同样的问题后,我遇到了以下帖子,这是我发现的所有内容中效果最好的。

       1 #####################
       2 # 1) Define the stages
       3 #####################
       4 
       5 stage { 'prereqs':
       6  before => Stage['main'],
       7 }
       8 
       9 stage { 'final':
      10  require => Stage['main'],
      11 }
      12 
      13 #####################
      14 # 2) Define the classes
      15 #####################
      16 
      17 # We don't care when this class is executed, it will
      18 # be included at random in the main stage
      19 class doThisWhenever1 {
      20 
      21 }
      22 
      23 # We don't care when this class is executed either, it will
      24 # be included at random in the main stage
      25 class doThisWhenever2 {
      26 
      27 }
      28 
      29 # We want this class to be executed before the
      30 # main stage
      31 class doThisFirst {
      32 
      33    exec {'firstThingsFirst':
      34      command => '/bin/echo firstThingsFirst',
      35    }
      36 }
      37 
      38 # We want this class to be executed after the
      39 # main stage
      40 class doThisLast {
      41 
      42   exec {'lastly':
      43      command => '/bin/echo lastly',
      44    }
      45 
      46 }
      47 
      48 #####################
      49 # 3) Assign the classes 
      50 # to a stage
      51 #####################
      52 
      53 class { 'doThisFirst': 
      54   stage => prereqs,
      55 }
      56 
      57 class { 'doThisLast':
      58  stage => final,
      59 }
      60 
      61 
      62 include doThisFirst
      63 include doThisLast   
      

      http://pipe-devnull.com/2013/09/20/puppet-ensure-class-execution-ordering.html

      问候

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-27
        • 1970-01-01
        • 2017-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-14
        • 1970-01-01
        相关资源
        最近更新 更多