Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from hw-cookbooks/attribute-and-lwrp

[COOK-2111] LWRP and attribute configuration
  • Loading branch information...
commit 714107ad629592c289cad9c71e667eaa5511824a 2 parents 30bc7be + 7dfaabf
Joshua Timberman jtimberman authored
13 README.md
View
@@ -35,8 +35,8 @@ from the data bag. The following attributes are used, in the
* `pgp_email` - the email address of the pgp key
* `pgp_fingerprint` - the finger print of the pgp key
-Data Bag
---------
+Data Bag based repository
+-------------------------
Create a data bag to store the repository information. It should be
named `reprepro`. The recipe uses the `main` data bag item.
@@ -92,6 +92,15 @@ named `reprepro`. The recipe uses the `main` data bag item.
* `pulls`: hash used in the pulls configuration.
* `architectures`: array of architectures to create in distributions configuration
+Attribute based configuration
+-----------------------------
+
+Configuration of the repository can also be driven via
+attributes. The same keys available for the data bag are
+available via node attributes with the exception of the
+`pgp` hash. Using attribute based configuration will have
+a PGP key pair auto generated on the node when it is built.
+
LICENSE AND AUTHOR
==================
14 attributes/default.rb
View
@@ -0,0 +1,14 @@
+default[:reprepro][:fqdn] = fqdn
+default[:reprepro][:listen_port] = 80
+default[:reprepro][:repo_dir] = "/srv/apt"
+default[:reprepro][:incoming] = "/srv/apt_incoming"
+default[:reprepro][:description] = "APT repository at #{fqdn}"
+default[:reprepro][:codenames] = [node.lsb.codename]
+default[:reprepro][:allow] = []
+default[:reprepro][:pulls][:name] = node.lsb.codename
+default[:reprepro][:pulls][:from] = node.lsb.codename
+default[:reprepro][:pulls][:component] = "main"
+default[:reprepro][:architectures] = %w(i386 amd64)
+default[:reprepro][:gnupg_home] = '/root/.gnupg'
+default[:reprepro][:enable_repository_on_host] = false
+default[:reprepro][:disable_databag] = false
2  metadata.rb
View
@@ -8,5 +8,7 @@
depends "build-essential"
depends "apache2"
+recommends "gpg"
+recommends "apt"
recipe "reprepro", "Installs and configures reprepro for an apt repository"
39 providers/deb.rb
View
@@ -0,0 +1,39 @@
+def load_current_resource
+ unless(new_resource.package)
+ new_resource.package new_resource.name
+ end
+ unless(new_resource.distribution)
+ new_resource.distribution node.lsb.codename
+ end
+end
+
+action :add do
+ p_name = %x{dpkg-deb -f #{new_resource.package} package}.strip
+ p_version = %x{dpkg-deb -f #{new_resource.package} version}.strip
+ e = execute "Add deb package (#{::File.basename(new_resource.package)})" do
+ command "reprepro -Vb #{node[:reprepro][:repo_dir]} includedeb #{new_resource.distribution} #{new_resource.package}"
+ cwd ::File.dirname(new_resource.package)
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if do
+ ex = %x{reprepro -b #{node[:reprepro][:repo_dir]} list #{new_resource.distribution} #{p_name}}
+ ex.to_s.strip.split(' ').last == p_version
+ end
+ end
+ new_resource.updated_by_last_action(e.updated_by_last_action?)
+end
+
+action :remove do
+ if(::File.exists?(new_resource.package))
+ p_name = %x{dpkg-deb -f #{new_resource.package} package}.strip
+ else
+ p_name = ::File.basename(new_resource.package.sub('.deb', ''))
+ end
+ e = execute "Remove package (#{::File.basename(new_resource.package)})" do
+ command "reprepro -Vb #{node[:reprepro][:repo_dir]} remove #{new_resource.distribution} #{p_name}"
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if do
+ %x{reprepro -b #{node[:reprepro][:repo_dir]} list #{new_resource.distribution} #{p_name}}.empty?
+ end
+ end
+ new_resource.updated_by_last_action(e.updated_by_last_action?)
+end
114 recipes/default.rb
View
@@ -18,17 +18,26 @@
# limitations under the License.
#
+node.set[:apache][:listen_ports] = node[:apache][:listen_ports] | Array(node[:reprepro][:listen_port])
+
include_recipe "build-essential"
include_recipe "apache2"
-apt_repo = data_bag_item("reprepro", "main")
-
-node.set_unless.reprepro.fqdn = apt_repo['fqdn']
-node.set_unless.reprepro.description = apt_repo['description']
-node.set_unless.reprepro.pgp_email = apt_repo['pgp']['email']
-node.set_unless.reprepro.pgp_fingerprint = apt_repo['pgp']['fingerprint']
-
-apt_repo_allow = apt_repo["allow"] || []
+unless(node[:reprepro][:disable_databag])
+ begin
+ apt_repo = data_bag_item("reprepro", "main")
+ node[:reprepro].keys.each do |key|
+ next if key.to_sym == :pgp
+ # NOTE: Use #has_key? so data bags can nil out existing values
+ node.default[:reprepro][key] = apt_repo[key] if apt_repo.has_key?(key)
+ end
+ node.default[:reprepro][:pgp_email] = apt_repo['pgp']['email']
+ node.default[:reprepro][:pgp_fingerprint] = apt_repo['pgp']['fingerprint']
+ rescue Net::HTTPServerException
+ Chef::Log.warn 'Data bag not found. Using default attribute settings!'
+ include_recipe 'gpg'
+ end
+end
ruby_block "save node data" do
block do
@@ -41,7 +50,7 @@
package pkg
end
-[ apt_repo["repo_dir"], apt_repo["incoming"] ].each do |dir|
+[ node[:reprepro][:repo_dir], node[:reprepro][:incoming] ].each do |dir|
directory dir do
owner "nobody"
group "nogroup"
@@ -50,7 +59,7 @@
end
%w{ conf db dists pool tarballs }.each do |dir|
- directory "#{apt_repo["repo_dir"]}/#{dir}" do
+ directory "#{node[:reprepro][:repo_dir]}/#{dir}" do
owner "nobody"
group "nogroup"
mode "0755"
@@ -58,45 +67,86 @@
end
%w{ distributions incoming pulls }.each do |conf|
- template "#{apt_repo["repo_dir"]}/conf/#{conf}" do
+ template "#{node[:reprepro][:repo_dir]}/conf/#{conf}" do
source "#{conf}.erb"
mode "0644"
owner "nobody"
group "nogroup"
variables(
- :allow => apt_repo_allow,
- :codenames => apt_repo["codenames"],
- :architectures => apt_repo["architectures"],
- :incoming => apt_repo["incoming"],
- :pulls => apt_repo["pulls"]
+ :allow => node[:reprepro][:allow],
+ :codenames => node[:reprepro][:codenames],
+ :architectures => node[:reprepro][:architectures],
+ :incoming => node[:reprepro][:incoming],
+ :pulls => node[:reprepro][:pulls]
)
end
end
-execute "import packaging key" do
- command "/bin/echo -e '#{apt_repo["pgp"]["private"]}' | gpg --import -"
- user "root"
- cwd "/root"
- not_if "gpg --list-secret-keys --fingerprint #{node[:reprepro][:pgp_email]} | egrep -qx '.*Key fingerprint = #{node[:reprepro][:pgp_fingerprint]}'"
+if(apt_repo)
+ pgp_key = "#{apt_repo["repo_dir"]}/#{node[:reprepro][:pgp_email]}.gpg.key"
+
+ execute "import packaging key" do
+ command "/bin/echo -e '#{apt_repo["pgp"]["private"]}' | gpg --import -"
+ user "root"
+ cwd "/root"
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ not_if "GNUPGHOME=/root/.gnupg gpg --list-secret-keys --fingerprint #{node[:reprepro][:pgp_email]} | egrep -qx '.*Key fingerprint = #{node[:reprepro][:pgp_fingerprint]}'"
+ end
+
+ template pgp_key do
+ source "pgp_key.erb"
+ mode "0644"
+ owner "nobody"
+ group "nogroup"
+ variables(
+ :pgp_public => apt_repo["pgp"]["public"]
+ )
+ end
+else
+ pgp_key = "#{node[:reprepro][:repo_dir]}/#{node[:gpg][:name][:email]}.gpg.key"
+ node.default[:reprepro][:pgp_email] = node[:gpg][:name][:email]
+
+ execute "sudo -u #{node[:gpg][:user]} -i gpg --armor --export #{node[:gpg][:name][:real]} > #{pgp_key}" do
+ creates pgp_key
+ end
+
+ file pgp_key do
+ mode 0644
+ owner "nobody"
+ group "nogroup"
+ end
+
+ execute "reprepro -Vb #{node[:reprepro][:repo_dir]} export" do
+ action :nothing
+ subscribes :run, resources(:file => pgp_key), :immediately
+ environment "GNUPGHOME" => node[:reprepro][:gnupg_home]
+ end
end
-template "#{apt_repo["repo_dir"]}/#{node[:reprepro][:pgp_email]}.gpg.key" do
- source "pgp_key.erb"
- mode "0644"
- owner "nobody"
- group "nogroup"
- variables(
- :pgp_public => apt_repo["pgp"]["public"]
- )
+if(node[:reprepro][:enable_repository_on_host])
+ include_recipe 'apt'
+
+ execute "apt-key add #{pgp_key}" do
+ action :nothing
+ if(apt_repo)
+ subscribes :run, resources(:template => pgp_key), :immediately
+ else
+ subscribes :run, resources(:file => pgp_key), :immediately
+ end
+ end
+
+ apt_repository "reprepro" do
+ uri "file://#{node[:reprepro][:repo_dir]}"
+ distribution node.lsb.codename
+ components ["main"]
+ end
end
template "#{node[:apache][:dir]}/sites-available/apt_repo.conf" do
source "apt_repo.conf.erb"
mode 0644
- owner "root"
- group "root"
variables(
- :repo_dir => apt_repo["repo_dir"]
+ :repo_dir => node[:reprepro][:repo_dir]
)
end
5 resources/deb.rb
View
@@ -0,0 +1,5 @@
+actions :add, :remove
+default_action :add
+
+attribute :package, :kind_of => String
+attribute :distribution, :kind_of => [String,Array]
2  templates/default/apt_repo.conf.erb
View
@@ -1,4 +1,4 @@
-<VirtualHost *:80>
+<VirtualHost *:<%= node[:reprepro][:listen_port] %>>
ServerAdmin <%= node[:reprepro][:pgp_email] %>
ServerName <%= node[:reprepro][:fqdn] %>
ServerAlias <%= node[:hostname] %> <%= node[:fqdn] %>
Please sign in to comment.
Something went wrong with that request. Please try again.