move things from modules/roles/static* to modules/static*
[mirror/dsa-puppet.git] / modules / staticsync / templates / 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 # this is the list of static mirrors, or, technically, the list of
14 # nodes with the roles::static_mirror class applied to it. this should
15 # be populated from outside the template from PuppetDB, see:
16 # modules/roles/manifests/static_base.pp
17 mirrors = @static_mirrors
18
19 config = YAML.load(File.open('/etc/puppet/modules/roles/misc/static-components.yaml').read)
20
21
22 config['mirrors'].each do |mirror, mc|
23         if not mirrors.include?(mirror)
24                 fail("static-components.yaml defines mirror #{mirror} but we do not know of it")
25         end
26 end
27
28 config['components'].each_pair do |component_name, component_conf|
29         %w{exclude-mirrors extra-push limit-mirrors}.each do |key|
30                 component_conf[key] = [] unless component_conf.has_key?(key)
31         end
32
33         srchost, srcpath = component_conf['source'].split(':', 2)
34
35         if not component_conf['exclude-mirrors'].empty? and \
36            not component_conf['limit-mirrors'].empty? then
37                 fail("Component #{component_name} specifies both exclude-mirrors and limit-mirrors.")
38         end
39
40         # In the end, we care about an exclude list, so let's invert limit-mirror and turn it into an exclude list
41         if not component_conf['limit-mirrors'].empty? then
42                 component_conf['exclude-mirrors'] = mirrors.select do |m|
43                         not component_conf['limit-mirrors'].include?(m)
44                 end
45         end
46
47         # mirrors may also specify limits as components-include (thus excluding all others).  Apply this
48         config['mirrors'].each do |mirror, mc|
49                 mirror_components_include = mc.fetch('components-include', [])
50                 next if mirror_components_include.empty?
51
52                 if not mirror_components_include.include?(component_name)
53                         next if component_conf['exclude-mirrors'].include?(mirror) # do not exclude twice
54                         component_conf['exclude-mirrors'] << mirror
55                 end
56         end
57
58         exclude = component_conf['exclude-mirrors'].sort().join(',')
59         exclude = '-' if exclude == ""
60         extrapush = component_conf['extra-push'].sort().join(',')
61         extrapush = '-' if extrapush == ""
62
63         lines << "#{component_conf['master']} #{component_name} #{srchost} #{srcpath} #{extrapush} #{exclude}"
64 end
65 lines.join("\n")
66 %>