a7234f981a014de808c10df826dd82fc4763bb69
[mirror/dsa-puppet.git] / modules / roles / templates / static-mirroring / static-components.conf.erb
1 ##
2 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
4 ##
5
6 <%=
7
8 lines = []
9
10 lines << "# This file has been autogenerated and pushed by puppet.  Edit static-components.yaml in puppet."
11 lines << "# <master> <service> <source host> <directory> <extra push hosts, comma separated> <hosts to not mirror this component to>"
12
13
14 config = YAML.load(File.open('/etc/puppet/modules/roles/misc/static-components.yaml').read)
15 mirrors = scope.lookupvar('site::roles')['static_mirror']
16
17 config['mirrors'].each do |mirror, mc|
18         if not mirrors.include?(mirror)
19                 fail("static-components.yaml defines mirror #{mirror} but we do not know of it")
20         end
21 end
22
23 config['components'].each_pair do |component_name, component_conf|
24         %w{exclude-mirrors extra-push limit-mirrors}.each do |key|
25                 component_conf[key] = [] unless component_conf.has_key?(key)
26         end
27
28         srchost, srcpath = component_conf['source'].split(':', 2)
29
30         if not component_conf['exclude-mirrors'].empty? and \
31            not component_conf['limit-mirrors'].empty? then
32                 fail("Component #{component_name} specifies both exclude-mirrors and limit-mirrors.")
33         end
34
35         # In the end, we care about an exclude list, so let's invert limit-mirror and turn it into an exclude list
36         if not component_conf['limit-mirrors'].empty? then
37                 component_conf['exclude-mirrors'] = mirrors.select do |m|
38                         not component_conf['limit-mirrors'].include?(m)
39                 end
40         end
41
42         # mirrors may also specify limits as components-include (thus excluding all others).  Apply this
43         config['mirrors'].each do |mirror, mc|
44                 mirror_components_include = mc.fetch('components-include', [])
45                 next if mirror_components_include.empty?
46
47                 if not mirror_components_include.include?(component_name)
48                         next if component_conf['exclude-mirrors'].include?(mirror) # do not exclude twice
49                         component_conf['exclude-mirrors'] << mirror
50                 end
51         end
52
53         exclude = component_conf['exclude-mirrors'].sort().join(',')
54         exclude = '-' if exclude == ""
55         extrapush = component_conf['extra-push'].sort().join(',')
56         extrapush = '-' if extrapush == ""
57
58         lines << "#{component_conf['master']} #{component_name} #{srchost} #{srcpath} #{extrapush} #{exclude}"
59 end
60 lines.join("\n")
61 %>