Author: ckauhaus
Date: Mon Oct 6 13:33:18 2008
New Revision: 6767
Log:
dynamic environment generation
Added:
gocept.infrastructure/testing/puppet/plugins/puppet/parser/functions/environments.rb
Modified:
gocept.infrastructure/testing/puppet/modules/app_admin/manifests/puppet.pp
gocept.infrastructure/testing/puppet/modules/app_admin/templates/puppet.conf.erb
gocept.infrastructure/testing/puppet/modules/net_analyzer/manifests/defines.pp
gocept.infrastructure/testing/puppet/modules/net_analyzer/templates/nagios_host.cfg.erb
Modified:
gocept.infrastructure/testing/puppet/modules/app_admin/manifests/puppet.pp
==============================================================================
---
gocept.infrastructure/testing/puppet/modules/app_admin/manifests/puppet.pp (original)
+++
gocept.infrastructure/testing/puppet/modules/app_admin/manifests/puppet.pp Mon
Oct 6 13:33:18 2008
(at)(at) -5,6 +5,8 (at)(at)
include tmpwatch
$puppet_root = "/home/puppet"
+ $envlist = environments("name", $puppet_root)
+ $envpaths = environments("path", $puppet_root)
$cron_minute = fqdn_rand(30)
package { "puppet": }
Modified:
gocept.infrastructure/testing/puppet/modules/app_admin/templates/puppet.conf.erb
==============================================================================
---
gocept.infrastructure/testing/puppet/modules/app_admin/templates/puppet.conf.erb (original)
+++
gocept.infrastructure/testing/puppet/modules/app_admin/templates/puppet.conf.erb Mon
Oct 6 13:33:18 2008
(at)(at) -1,7 +1,7 (at)(at)
[main]
server = <%= scope.lookupvar('location::puppetmaster') %>
- environments = production,testing,hotfix
+ environments = <%= envlist %>
# Where Puppet stores dynamic and growing data.
# The default value is '/var/puppet'.
(at)(at) -30,14 +30,11 (at)(at)
# Whether plugins should be synced with the central server.
pluginsync = true
-<% for env in ["production", "testing", "hotfix"] %>
-[<%= env %>]
- # Where the manifest is kept
- manifestdir = <%= puppet_root %>/<%= env %>/puppet/manifests
- manifest = <%= puppet_root %>/<%= env
%>/puppet/manifests/site.pp
-
- # Where modules are kept
- modulepath = <%= puppet_root %>/<%= env
%>/puppet/modules:/usr/share/puppet/modules
+<% for path in envpaths.split %>
+[<%= File.basename(path) %>]
+ manifestdir = <%= path %>/puppet/manifests
+ manifest = <%= path %>/puppet/manifests/site.pp
+ modulepath = <%= path %>/puppet/modules:/usr/share/puppet/modules
<% end %>
Modified:
gocept.infrastructure/testing/puppet/modules/net_analyzer/manifests/defines.pp
==============================================================================
---
gocept.infrastructure/testing/puppet/modules/net_analyzer/manifests/defines.pp (original)
+++
gocept.infrastructure/testing/puppet/modules/net_analyzer/manifests/defines.pp Mon
Oct 6 13:33:18 2008
(at)(at) -1,11 +1,11 (at)(at)
# Macros for easy definition of Nagios checks
-define net_analyzer::host($shortname, $alias = false) {
+define net_analyzer::host($shortname, $hostalias = false) {
$directory = "/etc/nagios/hosts/$fqdn"
$address = $title
- $hostalias = $alias ? {
+ $alias_ = $hostalias ? {
false => $fqdn,
- default => $alias
+ default => $hostalias
}
(at)(at)file {
Modified:
gocept.infrastructure/testing/puppet/modules/net_analyzer/templates/nagios_host.cfg.erb
==============================================================================
---
gocept.infrastructure/testing/puppet/modules/net_analyzer/templates/nagios_host.cfg.erb (original)
+++
gocept.infrastructure/testing/puppet/modules/net_analyzer/templates/nagios_host.cfg.erb Mon
Oct 6 13:33:18 2008
(at)(at) -1,6 +1,6 (at)(at)
define host {
host_name <%= shortname %>
- alias <%= hostalias %>
+ alias <%= alias_ %>
address <%= address %>
use generic-host
}
Added:
gocept.infrastructure/testing/puppet/plugins/puppet/parser/functions/environments.rb
==============================================================================
--- (empty file)
+++
gocept.infrastructure/testing/puppet/plugins/puppet/parser/functions/environments.rb Mon
Oct 6 13:33:18 2008
(at)(at) -0,0 +1,22 (at)(at)
+module Puppet::Parser::Functions
+ # Provide a list of environments found in puppet_root. Output format depends
+ # on the value of +fmt+:
+ # :name - comma-separated list of blank environment names, e.g.
+ # foo,bar,baz
+ # :path - space-separated list of pathname components, e.g.
+ # foo feature/bar feature/baz
+ newfunction(:environments, :type => :rvalue) do |args|
+ fmt = args[0].to_sym
+ root = args[1]
+ envs = (["#{root}/production", "#{root}/hotfix", "#{root}/testing"] + \
+ Dir["#{root}/feature/*/"]).map { |e| e.chomp('/') }
+ case fmt
+ when :name then
+ envs.map { |e| File.basename(e) }.join(',')
+ when :path then
+ envs.join(' ')
+ else
+ raise "environments: unsupported output format #{fmt}"
+ end
+ end
+end
|