Skip to content

Commit

Permalink
Added apt_repository LWRP for adding and removing repositories to /et…
Browse files Browse the repository at this point in the history
…c/apt/sources.list.d/

(cherry picked from commit 708fcd2f246c5f80316539d65df288313ff840f5)
  • Loading branch information
mattray authored and schisamo committed Dec 29, 2010
1 parent ac9fde8 commit 9a31edc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
36 changes: 30 additions & 6 deletions README.md
@@ -1,9 +1,17 @@
DESCRIPTION
Description
===========

Configures various APT components on Debian-like systems.
Configures various APT components on Debian-like systems. Also includes a LWRP.

RECIPES
Resources/Providers
===================

This cookbook contains an LWRP, `apt_repository`, which provides the `add` and `remove` actions for managing additional software repositories with entries in the `/etc/apt/sources.list.d/` directory.

* `add` takes a number of attributes and creates a repository file and builds the repository listing.
* `remove` deletes the `/etc/apt/sources.list.d/#{new_resource.repo_name}-sources.list` file identified by the `repo_name` passed as the resource name.

Recipes
=======

default
Expand All @@ -23,7 +31,7 @@ proxy

Installs the apt-proxy package and service so the system can be an APT proxy.

USAGE
Usage
=====

Put `recipe[apt]` first in the run list. If you have other recipes that you want to use to configure how apt behaves, like new sources, notify the execute resource to run, e.g.:
Expand All @@ -34,12 +42,28 @@ Put `recipe[apt]` first in the run list. If you have other recipes that you want

The above will run during execution phase since it is a normal template resource, and should appear before other package resources that need the sources in the template.

LICENSE AND AUTHOR
An example of The LWRP `apt_repository` `add` action:

apt_repository "zenoss" do
uri "http://dev.zenoss.org/deb"
distribution "main"
components ["stable"]
action :add
end

and the `remove` action:

apt_repository "zenoss" do
action :remove
end

License and Author
==================

Author:: Joshua Timberman (<joshua@opscode.com>)
Author:: Matt Ray (<matt@opscode.com>)

Copyright 2009, Opscode, Inc.
Copyright 2009, 2010 Opscode, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
26 changes: 26 additions & 0 deletions providers/repository.rb
@@ -0,0 +1,26 @@
action :add do
Chef::Log.info "Adding #{new_resource.repo_name} repository to /etc/apt/sources.list.d/#{new_resource.repo_name}-source.list"
#build our listing
repository = "deb"
repository = "deb-src" if new_resource.deb_src
repository = "#Created by the Chef apt_repository LWRP\n" + repository
repository += " #{new_resource.uri}"
repository += " #{new_resource.distribution}"
new_resource.components.each {|component| repository += " #{component}"}
#write out the file, replace it if it already exists
file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
owner "root"
group "root"
mode 0644
content repository + "\n"
action :create
end
end

action :remove do
Chef::Log.info "Removing #{new_resource.repo_name} repository from /etc/apt/sources.list.d/"
file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
action :delete
end
end

9 changes: 9 additions & 0 deletions resources/repository.rb
@@ -0,0 +1,9 @@
actions :add, :remove

#name of the repo, used for source.list filename
attribute :repo_name, :kind_of => String, :name_attribute => true
attribute :uri, :kind_of => String
#whether or not to add the repository as a source repo as well
attribute :deb_src, :default => false
attribute :distribution, :kind_of => String
attribute :components, :kind_of => Array, :default => []

0 comments on commit 9a31edc

Please sign in to comment.