2015-04-27 88 views
2

我正在嘗試使用exec資源類型來執行批處理文件。但是我想把變量$ dsn_64bit的值從init.pp傳遞給install.pp。請讓我知道如何做到這一點:在傀儡類中傳遞變量

這裏是我的init.pp

class exec_batchfile ($dsn_64bit = "false") 
{ 
if $::osfamily == 'windows' { 
include exec_batchfile::install 
    } 
    } 

這裏是我的install.pp

class exec_batchfile::install 
{ 
if $dsn_64bit == true 
{ 
    $hklm_path = 'HKLM\Software\Oracle' 
    $Script_name = 'E:\\Path\\pupp_test64.bat' 
} 
else 
{ 
    $hklm_path = 'HKLM\Software\WOW6432Node\Oracle' 
    $Script_name = 'E:\\Path\\pupp_test.bat' 
} 
    exec { 'exec_batchfile': 
     command => "${Script_name}", 
     path => $::path, 
     logoutput => true, 
     unless => "cmd.exe /c reg query ${hklm_path} /v inst_loc", 
    } 
} 

感謝

回答

2

由於傀儡2.7動態查找是已棄用,因此您的代碼將無法正常工作。現在推薦的解決方案是使用完全限定名稱。請按照link找到一個全面的解釋。

當你需要引用變量在另一個類中,給變量一個明確的命名空間:而不是簡單地指$ packagelist,使用$ git的核心:: :: packagelist。

+1

$ local_var =「from parent :: child」做了訣竅。鏈接爲+1。非常感謝 – user3605317

+0

更改了我的答案,使其更符合您的評論。 – kkamilpl