refactor static-components.conf.erb a bit - no logic changes yet
[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['components'].each_pair do |component, conf|
18         %w{exclude-mirrors extra-push}.each do |key|
19                 conf[key] = [] unless conf.has_key?(key)
20         end
21
22         srchost, srcpath = conf['source'].split(':', 2)
23
24         config['mirrors'].each do |mirror, mc|
25                 if mirrors.include?(mirror)
26                         if mc.has_key?('components-include') and not mc['components-include'].include?(component)
27                                 conf['exclude-mirrors'] << mirror
28                         end
29                 end
30         end
31
32         exclude = conf['exclude-mirrors'].join(',')
33         exclude = '-' unless exclude != ""
34         extrapush = conf['extra-push'].join(',')
35         extrapush = '-' unless extrapush != ""
36
37         lines << "#{conf['master']} #{component} #{srchost} #{srcpath} #{extrapush} #{exclude}"
38 end
39 lines.join("\n")
40 %>