Reputation: 111
After removing my variable names and everything extraneous for readability, my code comes down to this. I already set up a custom fact that returns an array of users that I need to set up some configuration files for. I'm trying to use a defined resource type and realize it with an array argument to do the configs for each user because Puppet lacks a basic for
loop, so the code I have simplifies to this:
define modulename::pushconfigs{
user {"$name":
ensure => present
parameter => value
parameter => value
parameter => value
}
}
modulename::setconfigs{$::userlist: }
# $::userlist is an array of users, in the form [user1 user2 user3...]
for a couple parameters. However, when I try to run it, it says couldn't
[do configs]for user user1 user2 user3
. In other words, it's realizing the defined type only once, and it's trying to do so for a user whose name is the concatenated array.
How can I instead realize the defined type for each one in the array?
Upvotes: 1
Views: 3894
Reputation: 573
$::userlist is a string.
Its a fact, and facts are strings.
You need to turn it into an array before you can iterate over it.
If $::userlist = "user1,user2,user3"
$a_userlist=split($::userlist,',')
modulename::setconfigs{$a_userlist: }
Upvotes: 0
Reputation: 11469
This should work...
define createuser{
user { $name :
ensure => present,
group => "gp",
home => "/home/$name",
shell => "/bin/bash",
}
}
$allusers = [ "user1", "user2", "user3", "user4" ]
createuser{$allusers:}
Upvotes: 1