2013-07-16 41 views
0

當我運行用木偶2.7.22以下木偶清單:傀儡定義類型是否在標準資源之後評估其資源?

Exec { 
    logoutput => true, 
    path  => '/bin', 
} 

define c { 
    exec {"echo [two]: ${b::x}": } 
} 

class a { 
    exec {"echo [one]: ${b::x}": } 
    include b 
} 

class b { $x = "asdf" } 

c {'two': } 
class {'a': } 

我收到以下輸出:

$ puppet apply test.pp 
warning: Scope(Class[A]): Could not look up qualified variable 'b::x'; class b has not been evaluated at /tmp/l/a.pp:11 
warning: Scope(Class[A]): Could not look up qualified variable 'b::x'; class b has not been evaluated at /tmp/l/a.pp:11 
notice: /Stage[main]//C[two]/Exec[echo [two]: asdf]/returns: [two]: asdf 
notice: /Stage[main]//C[two]/Exec[echo [two]: asdf]/returns: executed successfully 
notice: /Stage[main]/A/Exec[echo [one]: ]/returns: [one]: 
notice: /Stage[main]/A/Exec[echo [one]: ]/returns: executed successfully 
notice: Finished catalog run in 0.15 seconds 

現在我明白了木偶在解析順序計算的變量。我明白,在使用b的x變量的exec之後,包含來自class aclass b是愚蠢的。 我不明白的是,爲什麼定義的type c(名稱爲「2」的實例)中的exec具有$b::x的評估版本,即使它在分析順序方面看起來之前類「a」。

唯一可以解釋這一點的是,如果定義的類型在解析時被延遲?如果是這種情況,那麼(或任何地方)是否有來自puppetlabs的文檔和/或哪部分源代碼將標準與定義的類型資源區分開來? (我試過在compiler.rb中找到它,但失敗了)。

回答

0

您可以使用解決這個問題需要:

define c { 
    require b 
    notify {"echo [two]: ${b::x}": } 
} 

class a { 
    require b 
    notify {"echo [one]: ${b::x}": } 
} 

class b { $x = "asdf" } 

c {'two': } 
class {'a': } 

爲什麼定義的類型沒有按」我不知道這個警告是不是我所知道的,坦率地說我並不在意;它取決於Puppet編譯器的工作方式。如果你的清單依賴於這樣的代碼,它可能會破壞下一個版本的Puppet。