
我試圖讓木偶建立一個如下所示的配置檔案:
[All]
Hosts=apt-dater@puppetmaster;apt-dater@blaster; (etc...)
基本上,該檔案需要包含 apt-dater 類別的每個節點的條目。我一直在嘗試導出資源,但找不到將其組合在一起的乾淨方法。我應該如何建立這個文件?
答案1
我假設您已經了解匯出和收集單一類型資源的原理。只是不知道如何將這些單獨的資源轉換為單一檔案。 Puppet 有兩種方法可以做到這一點:
Augeas 是一個非常聰明的工具,但如果您必須開始編寫和分發自己的鏡頭,它可能會很複雜。不過puppet-concat
很容易掌握。我還沒有測試以下語法,但它應該會讓您走上正確的軌道:
# apt-dater/manifests/server.pp
class apt-dater::server {
file { "/somepath/apt-dater/hosts.conf": }
concat::fragment{ "apt-dater_hosts_header":
content => "[All]\nHosts=",
order => 1,
}
Apt-dater::Client <<| |>>
}
# apt-dater/manifests/defines/register.pp
define apt-dater::register($order=10) {
concat::fragment{ "apt-dater_hosts_$name":
target => "/somepath/apt-dater/hosts.conf",
content => "apt-dater@${name};",
}
}
# apt-dater/manifests/client.pp
class apt-dater::client {
@apt-dater::register{ "$hostname": }
}
然後設定節點:
# On the central server.
include apt-dater::server
# On each of the client nodes.
include apt-dater::client