public
Last active

Puppet Module : No Code In Data ~ Externalize Data into separately managed CSV files

  • Download Gist
common.csv
1 2 3 4 5 6
# $MANIFESTPATH/extdatadir/common.csv
 
httpd_conf_dir,/etc/httpd/conf.d
httpd_is_cgi,true
httpd_git_path,/var/www/git
httpd_git_url,/mygit
env_testnode.csv
1 2 3
# $MANIFESTPATH/extdatadir/env_testnode.csv
 
httpd_git_url,/testgit
git.pp
Puppet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# $MODULEPATH/httpd/manifests/git.pp
 
class httpd::git {
 
$conf_dir = extlookup('httpd_conf_dir')
$is_cgi = extlookup('httpd_is_cgi')
$path = extlookup('httpd_git_path')
$url = extlookup('httpd_git_url')
 
 
file {
"${conf_dir}/git.conf":
ensure => 'present',
content => template('httpd/mynode.conf.erb'),
}
}
mynode.conf.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11
# $MODULEPATH/httpd/templates/mynode.conf.erb
 
Alias <%= url %> <%= path %>
 
<Directory <%= path %>>
<% if is_cgi === 'true' %> # because from CSV any (boolean) value will be read as string
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi
<% end %>
</Directory>
run_puppet.sh
Shell
1
puppet apply --environment=testnode --modulepath=$MODULEPATH --manifestdir=$MANIFESTPATH $MANIFESTPATH/site.pp
site.pp
Puppet
1 2 3 4 5 6
# $MANIFESTPATH/site.pp
 
$extlookup_datadir = "${settings::manifestdir}/extdatadir"
$extlookup_precedence = ["%{fqdn}", "env_%{environment}", "domain_%{domain}", "common"]
 
include httpd::git

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.