Attempt to configure an apache vhost for a static component only if it exists on...
authorPeter Palfrader <peter@palfrader.org>
Sat, 2 Jan 2016 19:58:00 +0000 (19:58 +0000)
committerPeter Palfrader <peter@palfrader.org>
Sat, 2 Jan 2016 19:58:00 +0000 (19:58 +0000)
modules/puppetmaster/lib/puppet/parser/functions/has_static_component.rb [new file with mode: 0644]
modules/roles/templates/static-mirroring/vhost/planet.debian.org.erb

diff --git a/modules/puppetmaster/lib/puppet/parser/functions/has_static_component.rb b/modules/puppetmaster/lib/puppet/parser/functions/has_static_component.rb
new file mode 100644 (file)
index 0000000..cd04cdc
--- /dev/null
@@ -0,0 +1,37 @@
+module Puppet::Parser::Functions
+  newfunction(:has_static_component, :type => :rvalue) do |args|
+      static_component = args[0]
+      fqdn = lookupvar('fqdn')
+
+      cfg = YAML.load(File.open('/etc/puppet/modules/roles/misc/static-components.yaml').read)
+
+      if cfg.include?('mirrors')
+        if cfg['mirrors'].include?(fqdn)
+          if cfg['mirrors'][fqdn].include?('components-include')
+            if cfg['mirrors'][fqdn]['components-include'].include?(static_component)
+              return true
+            else
+              return false
+            end
+          end
+        end
+      end
+
+      if cfg.include?('components')
+        if cfg['components'].include?(static_component)
+          if cfg['components'][static_component].include?('exclude-mirrors')
+            if cfg['components'][static_component]['exclude-mirrors'].include?(fqdn)
+              return false
+            else
+              return true
+            end
+          else
+            return true
+          end
+        end
+      end
+
+      err "Static component #{static_component} appears to be not defined"
+      return false
+  end
+end
index 758771c..20f9298 100644 (file)
@@ -1,3 +1,5 @@
+<% if scope.function_has_static_component(['planet.debian.org']) -%>
+
 <Virtualhost <%= vhost_listen %> >
        ServerName planet.debian.org
        ServerAlias planet.debian.net planeta.debian.net planet-backend.debian.org planet-fastly.debian.org planet-maxcdn.debian.org
@@ -24,4 +26,6 @@
        RewriteCond %{HTTP_HOST} ^planet.debian.net$ [NC]
        RewriteRule ^/(.*)        http://planet.debian.org/$1  [R=permanent,L]
 </VirtualHost>
+<% end -%>
+
 # vim:set syn=apache: