Last active
January 1, 2016 00:49
-
-
Save s0enke/8068807 to your computer and use it in GitHub Desktop.
this is an example usage of iterators in puppet 3.4
This file contains 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
# challenge: write an ini file from hiera input | |
# $cache_cluster_instances = [ | |
# { host => 'cache-a', weight => 1 }, | |
# { host => 'cache-b', weight => 0.5 }, | |
# { host => 'cache-c', weight => 0.5 }, | |
# ] | |
$cache_cluster_instances = hiera('cache_cluster_instances') | |
$cache_cluster_instances.each |$i, $cache_cluster_instance| { | |
Ini_Setting { | |
ensure => present, | |
path => '/tmp/myapp.ini', | |
} | |
ini_setting { "cache_instance${i}_host" : | |
section => 'cache_cluster', | |
setting => "${i}.host", | |
value => $cache_cluster_instance['host'], | |
} | |
ini_setting { "cache_instance${i}_weight" : | |
section => 'cache_cluster', | |
setting => "${i}.weight", | |
value => $cache_cluster_instance['weight'], | |
} | |
} | |
### | |
# "with create_resources": | |
### | |
# $cache_cluster_instances = [ | |
# { host => 'cache-a', weight => 1 }, | |
# { host => 'cache-b', weight => 0.5 }, | |
# { host => 'cache-c', weight => 0.5 }, | |
# ] | |
$cache_cluster_instances = hiera('cache_cluster_instances') | |
cache_cluster_instances_to_ini('my cache cluster', $cache_cluster_instances) | |
define cache_cluster_instances_to_ini( | |
$instances | |
) { | |
$ini_settings_defaults = { | |
ensure => present, | |
path => '/tmp/myapp.ini', | |
} | |
$ini_settings = { | |
"cache_instance${i}_host" => { | |
section => 'cache_cluster', | |
setting => "${1}.host", | |
value => $cache_cluster_instance['host'], | |
}, | |
"cache_instance${i}_weight" => { | |
section => 'cache_cluster', | |
setting => "${1}.weight", | |
value => $cache_cluster_instance['weight'], | |
} | |
} | |
create_resources('ini_setting', $ini_settings, $ini_settings_defaults) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment