Puppet Nodes.pp包含模块执行顺序

时间:2012-10-10 18:50:00

标签: provisioning puppet

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

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. windowsrolesfeatures
  3. anyotherpackage {hg,netfx ...}(不关心配置顺序) ñ。 tcbase
  4. tcuigant(最后一个)

4 个答案:

答案 0 :(得分:1)

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

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

GER。

答案 1 :(得分: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 !
      ;
}

但这很丑陋,这不是制作的阶段。

答案 2 :(得分:1)

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

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计算机配置模块不依赖于彼此,但myserver1与sqlexpress2008取决于该基准。

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

答案 3 :(得分:1)

在发布同样的问题之后,我发现了以下帖子,其中我发现的所有内容都是最好的。

 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

此致