From 1362b4f85261e2181197e83c94e989b39f15f3a6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 21 Oct 2016 11:49:30 +0100 Subject: [PATCH 1/1] Update the openstreetmap PPA on every run --- cookbooks/apt/providers/source.rb | 63 ------------------------------- cookbooks/apt/recipes/default.rb | 17 +++++---- cookbooks/apt/resources/source.rb | 59 +++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 79 deletions(-) delete mode 100644 cookbooks/apt/providers/source.rb diff --git a/cookbooks/apt/providers/source.rb b/cookbooks/apt/providers/source.rb deleted file mode 100644 index d3b710b85..000000000 --- a/cookbooks/apt/providers/source.rb +++ /dev/null @@ -1,63 +0,0 @@ -# -# Cookbook Name:: apt -# Provider:: apt_source -# -# Copyright 2015, OpenStreetMap Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -def whyrun_supported? - true -end - -use_inline_resources - -action :create do - if new_resource.key - execute "apt-key-#{new_resource.key}-clean" do - command "/usr/bin/apt-key adv --batch --delete-key --yes #{new_resource.key}" - only_if "/usr/bin/apt-key adv --list-keys #{new_resource.key} | fgrep expired" - end - - if new_resource.key_url - execute "apt-key-#{new_resource.key}-install" do - command "/usr/bin/apt-key adv --fetch-keys #{new_resource.key_url}" - not_if "/usr/bin/apt-key adv --list-keys #{new_resource.key}" - end - else - execute "apt-key-#{new_resource.key}-install" do - command "/usr/bin/apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys #{new_resource.key}" - not_if "/usr/bin/apt-key adv --list-keys #{new_resource.key}" - end - end - end - - template source_path do - source new_resource.template - owner "root" - group "root" - mode 0o644 - variables :url => new_resource.url - end -end - -action :delete do - file source_path do - action :delete - end -end - -def source_path - "/etc/apt/sources.list.d/#{new_resource.name}.list" -end diff --git a/cookbooks/apt/recipes/default.rb b/cookbooks/apt/recipes/default.rb index 74766e6e8..57c279cd6 100644 --- a/cookbooks/apt/recipes/default.rb +++ b/cookbooks/apt/recipes/default.rb @@ -69,17 +69,18 @@ end apt_source "openstreetmap" do url "http://ppa.launchpad.net/osmadmins/ppa/ubuntu" key "D57F48750AC4F2CB" + update true end apt_source "management-component-pack" do - template "hp.list.erb" + source_template "hp.list.erb" url "http://downloads.linux.hpe.com/SDR/repo/mcp" key "C208ADDE26C2B797" key_url "https://downloads.linux.hpe.com/SDR/hpePublicKey2048_key1.pub" end apt_source "hwraid" do - template "hwraid.list.erb" + source_template "hwraid.list.erb" url "http://hwraid.le-vert.net/ubuntu" key "6005210E23B3D3B4" end @@ -90,25 +91,25 @@ apt_source "mapnik-v210" do end apt_source "nginx" do - template "nginx.list.erb" + source_template "nginx.list.erb" url "http://nginx.org/packages/ubuntu" key "ABF5BD827BD9BF62" end apt_source "elasticsearch" do - template "elasticsearch.list.erb" + source_template "elasticsearch.list.erb" url "http://packages.elasticsearch.org/elasticsearch/1.7/debian" key "D27D666CD88E42B4" end apt_source "logstash" do - template "elasticsearch.list.erb" + source_template "elasticsearch.list.erb" url "http://packages.elasticsearch.org/logstash/2.3/debian" key "D27D666CD88E42B4" end apt_source "logstash-forwarder" do - template "elasticsearch.list.erb" + source_template "elasticsearch.list.erb" url "http://packages.elasticsearch.org/logstashforwarder/debian" key "D27D666CD88E42B4" end @@ -119,13 +120,13 @@ apt_source "passenger" do end apt_source "postgresql" do - template "postgresql.list.erb" + source_template "postgresql.list.erb" url "http://apt.postgresql.org/pub/repos/apt" key "7FCC7D46ACCC4CF8" end apt_source "mediawiki" do - template "mediawiki.list.erb" + source_template "mediawiki.list.erb" url "https://releases.wikimedia.org/debian" key "90E9F83F22250DD7" end diff --git a/cookbooks/apt/resources/source.rb b/cookbooks/apt/resources/source.rb index 83fc3577f..44bd100ae 100644 --- a/cookbooks/apt/resources/source.rb +++ b/cookbooks/apt/resources/source.rb @@ -17,14 +17,14 @@ # limitations under the License. # -actions :create, :delete default_action :create -attribute :name, :kind_of => String, :name_attribute => true -attribute :template, :kind_of => String, :default => "default.list.erb" -attribute :url, :kind_of => String, :required => true -attribute :key, :kind_of => String -attribute :key_url, :kind_of => String +property :name, String, :name_property => true +property :source_template, String, :default => "default.list.erb" +property :url, String, :required => true +property :key, String +property :key_url, String +property :update, [TrueClass, FalseClass], :default => false def initialize(name, run_context = nil) super(name, run_context) @@ -32,6 +32,49 @@ def initialize(name, run_context = nil) @action = node[:apt][:sources].include?(name) ? :create : :delete end -def after_created - notifies :run, "execute[apt-update]", :immediately if @action == :create +action :create do + if key + execute "apt-key-#{key}-clean" do + command "/usr/bin/apt-key adv --batch --delete-key --yes #key}" + only_if "/usr/bin/apt-key adv --list-keys #{key} | fgrep expired" + end + + if key_url + execute "apt-key-#{key}-install" do + command "/usr/bin/apt-key adv --fetch-keys #{key_url}" + not_if "/usr/bin/apt-key adv --list-keys #{key}" + notifies :run, "execute[apt-update-#{new_resource.name}]" + end + else + execute "apt-key-#{key}-install" do + command "/usr/bin/apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys #{key}" + not_if "/usr/bin/apt-key adv --list-keys #{key}" + notifies :run, "execute[apt-update-#{new_resource.name}]" + end + end + end + + template source_path do + source source_template + owner "root" + group "root" + mode 0o644 + variables :url => url + notifies :run, "execute[apt-update-#{new_resource.name}]" + end + + execute "apt-update-#{name}" do + action update ? :run : :nothing + command "/usr/bin/apt-get update --no-list-cleanup -o Dir::Etc::sourcelist='#{source_path}' -o Dir::Etc::sourceparts='-'" + end +end + +action :delete do + file source_path do + action :delete + end +end + +def source_path + "/etc/apt/sources.list.d/#{name}.list" end -- 2.39.5