2012-10-10 22 views
5

Sto cercando di impostare un ordine sequenziale su alcuni dei miei moduli per determinati nodi.Puppet Nodes.pp Includi moduli Ordine di esecuzione

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'] 
} 

Certamente NON voglio impostare le dipendenze all'interno delle risorse del modulo perché questo renderà loro interdipendenti che io non voglio fare. In questo caso, voglio eseguire questo ordine.

  1. ps (primo)
  2. windowsrolesfeatures
  3. anyotherpackage {hg, netfx ...} (dont care l'ordine di provisioning) n. tcbase
  4. tcuigant (ultimo)

risposta

1

Se davvero non si desidera esprimere relazioni tra i moduli, è possibile utilizzare le fasi per far rispettare un ordine.

È innanzitutto necessario dichiarare le tappe della tua manifesta in alto:

## 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] 

poi usarli:

# 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 ! 
     ; 
} 

Ma questo è brutto e non è questo che le fasi sono fatti per.

+1

Immagino di non avere altra scelta. 1. Creare una relazione tra le risorse anche se appartengono a moduli diversi.Esempio (netfx40, netfx45, sql2012). In questo caso ho tre moduli ma la catena di dipendenze è come è stata dichiarata sql2012-> netfx45-> netfx40. Supponendo che non è possibile ridistribuire il modulo sql2012 senza gli altri moduli. 2. Usando le fasi sto creando le relazioni al livello più alto ma le risorse non sono più indipendenti poiché hanno uno "stage" variabile che deve essere impostato sul sito.pp – Maverick

1

Vorrei suggerire riscrivere i moduli in modo che l'ordine in cui sono installati non è importante più o creare le relazioni necessarie alle risorse.

Se si sta installando/configurando risorse correlate da moduli diversi, è possibile considerare l'unione di tali moduli.

Ger.

+0

Se creo relazioni tra le risorse allora si stanno facendo le risorse provenienti da diversi moduli dipendente e voglio creare quel rapporto al livello più alto, ma utilizzando stadi sembrano davvero brutto . – Maverick

+0

Bel nome! Immagino un orso dalle lunghe sbarre che getta mele giù, volenti o nolenti, su un ignaro pic-nic. –

1

Credo di risolverlo utilizzando un approccio diverso con l'ereditarietà del nodo.

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 
} 

moduli di configurazione macchina Windows non dipendono l'uno dall'altro ma myserver1 con la sqlexpress2008 dipende quella di base.

Nessuna fase o dipendenza del modulo !!!!!

1

Dopo aver rilasciato lo stesso problema mi sono imbattuto nel post seguente che funziona meglio di tutto ciò che ho trovato.

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

saluti