[英]puppet hiera array, loop and hash
我目前在hiera / puppet之間存在一個問題:
在我的等級中,我有:
mysql_user_mgmt:
- mysql_user: 'toto@localhost'
mysql_hash_password: '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29'
mysql_grant_user: 'toto@localhost/*.*'
mysql_user_table_privileges: '*.*'
- mysql_user: 'test@localhost'
mysql_hash_password: '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29'
mysql_grant_user: 'test@localhost/*.*'
mysql_user_table_privileges: '*.*'
在我的木偶中,我試圖做一個循環以從hiera獲取數據:
$mysql_user_mgmt = hiera('mysql_user_mgmt',undef)
define mysql_loop () {
$mysql_hash_password = $name['mysql_hash_password']
notify { "mysql_hash_password: ${mysql_hash_password}": }
}
mysql_loop { $mysql_user_mgmt: }
但是我遇到了一些奇怪的錯誤。 有人可以幫我弄清楚如何制作循環嗎?
資源標題是字符串 。 總是。
您正在嘗試使用mysql_loop
資源的標題將哈希輸入到類型定義。 那行不通。 最終將使用哈希的字符串化版本,並且您以后通過哈希索引檢索組件的嘗試將失敗,可能是某種類型的錯誤。
您有幾種選擇:
您可以稍微重新定義定義和數據,然后將匯總數據作為哈希參數傳遞。 (下面的示例。)
您可以稍微重新定義定義和數據,然后使用create_resources()
函數。
如果您已經升級到Puppet 4,或者願意在Puppet 3中啟用將來的解析器,則可以使用new(ish)循環函數之一,例如each()
。
備選方案(1)的示例:
將數據重新組織為散列的哈希,並以用戶ID鍵入:
mysql_user_mgmt:
'toto@localhost':
mysql_hash_password: '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29'
mysql_grant_user: 'toto@localhost/*.*'
mysql_user_table_privileges: '*.*'
'test@localhost':
mysql_hash_password: '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29'
mysql_grant_user: 'test@localhost/*.*'
mysql_user_table_privileges: '*.*'
修改定義:
define mysql_user ($all_user_info) {
$mysql_hash_password = $all_user_info[$title]['mysql_hash_password']
notify { "mysql_hash_password: ${mysql_hash_password}": }
}
像這樣使用它:
$mysql_user_mgmt = hiera('mysql_user_mgmt',undef)
$mysql_user_ids = keys($mysql_user_mgmt)
mysql_user { $mysql_user_ids: all_user_info => $mysql_user_mgmt }
( keys()
函數可從puppetlabs-stdlib模塊中獲得。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.