Apt

具有一個公共資源的不同 puppet 模組

  • May 2, 2012

我正在為我的伺服器的不同角色編寫特定的模組。所以我有一個puppet和一個puppet-dashboard -Module。puppet模組確保 puppet 安裝正確。puppet-dashboard 對 puppet-dashboard做同樣的事情,當然。

這兩個模組都需要 puppetlabs apt 源(順便說一句。我正在使用https://github.com/puppetlabs/puppet-apt)。所以我在puppetpuppet-dashboard -module中有以下定義的資源:

   apt::source { "puppetlabs":
     location          => "http://apt.puppetlabs.com",
     release           => "squeeze",
     repos             => "main",
     required_packages => true,
     include_src       => false,
     key               => "4BD6EC30",
     key_server        => "pgp.mit.edu",
   }

現在我的代理出現以下錯誤:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Apt::Source[puppetlabs] is already declared in file /etc/puppet/modules/puppet/manifests/base.pp at line 27; cannot redeclare at /etc/puppet/modules/puppet-dashboard/manifests/init.pp:42 on node server123

特定模組彼此獨立。因此我認為在每個模組中分別設置這個apt源的依賴是正確的。

一種解決方法是將一個源重命名為puppetlabstopuppetlabs2或 sth。像那樣。但必須有另一種解決方案。

我很好奇你的回答!

每當我遇到這個問題(尤其是包中常見的問題)時,我只是將資源單獨放在一個類中:

class git {
   package { 'git': ensure => installed, }
}

然後我包含類而不是定義資源。

下一個問題:但它們被不同的模組使用!是的,要麼把它們放在 中,要麼放在common其他一些特定於模組的公共模組中(比如,puppet-common)。

有幾種方法可以解決這個問題。我會親自將您的 apt 源拆分為一個單獨的類,然後使用包含或繼承(取決於具體情況)將該類拉到您需要的任何地方。

引用自:https://serverfault.com/questions/385346