Created
September 8, 2012 23:08
-
-
Save nfisher/3680788 to your computer and use it in GitHub Desktop.
Array concatenation, scoped variables and templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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