2012-10-10 84 views
5

我想在某些模塊上爲某些節點設置順序順序。Puppet Nodes.pp包含模塊執行順序

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(最後一個)

回答

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

我想我沒有其他選擇。 1.創建資源之間的關係,即使它們屬於不同的模塊。實施例(netfx40,netfx45,sql2012)。在這種情況下,我有三個模塊,但依賴鏈的聲明是sql2012-> netfx45-> netfx40。猜測你不能在沒有其他模塊的情況下重新分配sql2012模塊。 2.通過使用階段,我在頂層創建關係,但資源不再獨立,因爲它們有一個需要在站點設置的變量「階段」.pp – Maverick

1

我會強烈建議重寫模塊,這樣它們所安裝的順序並不重要了,或創建的資源必要的關係。

如果您要從不同模塊安裝/配置相關資源,可以考慮合併這些模塊。

Ger。

+0

如果我創造,那麼你正在從不同的模塊的資源依賴,我也想創建在頂級這種關係,但使用的資源之間的關係階段,看起來真的很醜陋。 – Maverick

+0

偉大的名字!我想象着一隻小熊在一個毫無戒心的野餐會上投擲蘋果。 –

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取決於基線。

沒有階段或模塊依賴項!!!!!

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

問候