Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to do add-apt-repository via Chef?

I'm learning Chef and I'm going to do right now for Ubuntu:

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

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

but may be there is a better ("chef-style"?) way to do it. Also, I concerned that sometimes add-apt-repository waits for "Enter" key on it's execution, so this approach might not work as is. What is the Right way of doing it?

Edit: I only have ppa link in format: ppa:something/user

like image 397
Artem Avatar asked Mar 06 '12 00:03

Artem


People also ask

How do I manually add apt to repository?

To add repositories manually in ubuntu edit the /etc/apt/sources. list file and add the apt repository line to the file. Personal Package Archives (PPA) allows you to upload Ubuntu source packages that are built and published with Launchpad as an apt repository.

What is ADD-apt-repository PPA?

sudo add-apt-repository <PPA_info> <– This command adds the PPA repository to the list. sudo apt-get update <– This command updates the list of the packages that can be installed on the system. sudo apt-get install <package_in_PPA> <– This command installs the package.

What is apt repository?

What is an APT repository? An APT repository is a collection of deb packages with metadata that is readable by the apt-* family of tools, namely, apt-get . Having an APT repository allows you to perform package install, removal, upgrade, and other operations on individual packages or groups of packages.


3 Answers

If you use chef v12.9 and above, Use the apt_repository resource for managing apt repositories. If you use chef lower than v12.8, you can use APT Cookbook provided by Chef Software, Inc. This cookbook provides same LWRP Following is the example usage of the resource:

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
like image 86
Leo Gamas Avatar answered Oct 06 '22 14:10

Leo Gamas


There is also a third-party apt cookbook that provides a ppa method:

ppa "user/repo"

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

Ideally this functionality should be added to the opscode apt cookbook.

like image 43
Eric Drechsel Avatar answered Oct 06 '22 13:10

Eric Drechsel


Adding another answer since I just found myself back here. If you just have the URL for a key and not the key signature you can simply specify the URL in the key attribute:

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

From the documentation

like image 42
jorfus Avatar answered Oct 06 '22 14:10

jorfus