Skip to content

Instantly share code, notes, and snippets.

@nfisher
Created September 8, 2012 23:08
Show Gist options
  • Save nfisher/3680788 to your computer and use it in GitHub Desktop.
Save nfisher/3680788 to your computer and use it in GitHub Desktop.
Array concatenation, scoped variables and templates
# Given the configuration below.
# Expected results list of users in bip.conf.
# Actual results in an empty file.
# bip.conf
<%
usernames = scope.lookupvar('users::usernames')
fullnames = scope.lookupvar('users::fullnames')
-%>
<% usernames.each_with_index(username, index) do -%>
<%= username %>
<%= fullnames[index] %>
<% end -%>
# EOF bip.conf
# bip init.pp
class bip {
include users
package { 'bip':
ensure => latest,
}
file { 'bip.conf':
ensure => file,
path => '/etc/bip.conf',
owner => 'root',
group => 'bip',
mode => '0640',
content => template('bip/bip.conf'),
require => [Class['users'], Package['bip']],
}
}
# EOF bip.pp
# irc.pp
define users::irc($key, $fullname, $ensure = 'present', $username = $title, $type = 'rsa') {
include users
$users::usernames += [$username]
$users::fullnames += [$fullname]
# etc...
# EOF irc.pp
# users init.pp
class users {
$usernames = []
$fullnames = []
# EOF users init.pp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment