2012-03-06 94 views
47

我学厨师,我要现在的Ubuntu做:通过厨师做add-apt-repository的正确方法是什么?

execute "add-apt-repository ppa:#{node[:some_repo]}" do 
    user "root" 
end 

execute "apt-get update" do 
    user "root" 
end 

,但可能有一个更好的(“大厨式”?)的方式来做到这一点。另外,我担心有时add-apt-repository会在执行时等待“Enter”键,所以这种方法可能无法正常工作。什么是正确的做法?

编辑:我只有在格式PPA链接:PPA:东西/用户

回答

62

如果使用chef v12.9以上,使用apt_repository资源管理Apt库。如果您使用低于v12.8的厨师,则可以使用APT Cookbook provided by Chef Software, Inc。这本食谱提供相同LWRP 以下是资源的使用例子:

apt_repository "nginx-php" do 
    uri "http://ppa.launchpad.net/nginx/php5/ubuntu" 
    distribution node['lsb']['codename'] 
    components ["main"] 
    keyserver "keyserver.ubuntu.com" 
    key "C300EE8C" 
end 
+2

如何找出什么是关键服务器和关键,如果我只有PPA名称/用户名? – Artem 2012-03-06 18:20:58

+0

我不知道如何获得密钥,但我几乎可以确定的密钥服务器与上述密钥服务器相同:“keyserver.ubuntu.com” – 2012-03-07 15:46:08

+0

PPA将提供有关密钥服务器和密钥的信息。 – jtimberman 2012-03-09 15:31:42

16

还有一个第三方容易食谱,提供了ppa方法:

ppa "user/repo" 

https://github.com/sometimesfood/chef-apt-repo

理想这个功能应该添加到opscode apt Cookbook中。

+0

ppa方法对于上面Leo Gamas回答中提到的apt_repository LWRP有什么功能? – DonBecker 2014-07-14 16:33:42

+0

我们过去也建立了自己的室内设计。最近,这一切都利用了社区食谱。在能力方面存在太多的边缘案例,并且有效地发现知识库需要关注。:)在这种情况下,您只需提供完整的启动板URL到repo,而不仅仅是'user/repo',它将与'apt_repository'配合使用。 – Till 2014-08-01 14:48:29

2

另外需要注意的是,一旦你添加了aptbook,你应该添加一个依赖声明到你的食谱中。 更新metadata.rb(应该在你的食谱目录的基础)

depends 'apt', '>= 2.7.0' 

这将防止故障模式,因为它不具备容易菜谱在它的运行列表中的节点无法更新。

5

添加另一个答案,因为我刚刚回到这里。 如果你只是有一个键的网址,而不是关键的签名,你可以简单地指定要在关键属性的网址:

apt_repository 'some_repo' do 
    uri   'http://some_url/ubuntu/precise/amd64/' 
    arch   'amd64' 
    distribution 'precise' 
    components ['contrib'] 
    key   'https://some_key_url.com/debian/release.key' 
end 

the documentation