How to iterate on puppet? Or how to avoid it? -


i have global string variable that's array of names:

"mongo1,mongo2,mongo3"

what i'm doing here splitting them array using "," delimiter , feeding array define create instances need.

problem is, every instance has different port. made new stdlib function index of name in array, , feeding port parameter.

this seems bad , don't having alter stdlib.

so i'm wondering how using nx2 array?

"mongo1,port1;mongo2,port2;mongo3,port3"

or 2 arrays

"mongo1,mongo2,mongo3" , "port1,port2,port3"

class site::mongomodule {   class { 'mongodb':     package_ensure => '2.4.12',     logdir         => '/var/log/mongodb/'   }    define mongoconf () {     $index = array_index($::site::mongomodule::mongoreplsetname_array, $name)      mongodb::mongod { "mongod_${name}":       mongod_instance => $name,       mongod_port     => 27017 + $index,       mongod_replset  => 'shard1',       mongod_shardsvr => 'true',     }   }    $mongoreplsetname_array = split(hiera('site::mongomodule::instances', undef), ',')    mongoconf { $mongoreplsetname_array: } } 

the module i'm using one:

https://github.com/echocat/puppet-mongodb


using puppet 3.8.0

hiera can give hash when lookup key, can have in hiera:

mongoinstances:   mongo1:     port: 1000   mongo2:     port: 1234 

then lookup key in hiera hash, , pass create_resources function create 1 instance of resource per entry in hash.

$mongoinstances = hiera('mongoinstances') create_resources('mongoconf', $mongoinstances) 

you need change mongoconf work adding $port parameter. each time want pass additional value hiera, add parameter defined type.


Comments