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