Looping through a recipe

Hi There,
I'm trying to write a recipe for windows server to create a local user and add to the remote desktop group.

I'm able to do this for 1 user and i want to do this for 300 users, like testuser1,testuser2...testuser300. Can someone help how can i expand this recipe to work using array etc. I'm new to Ruby.

user "testuser1" do
password "safepass"
end

group "Remote Desktop Users" do
action :modify
members "testuser1"
append true
end

I would probably do something like this.

.each do |username|

user username

password “safepass”

end

group “Remote Desktop Users” do

action :modify

members username

append true

end

end

It would appear something screwy happened with my response

So lets try this again.

object_of_users.each do |username|

user username

password “safepass”

end

group ‘Remote Desktop Users’ do

action :modify

members username

append true

end

end

Not being sure how you were going to pass that list of users into this I am using object_of_users as the array that the code will loop thru.

I use a version of this:

eg
attributes:

default[:localusers] = {
osg: {
remove: %w(
junkuser1
junkuser2
junkuser3
osghcc01
),
add: {
osgcms01: {
'username' => 'osgcms01',
'comment' => 'OSG account for CMS',
'uid' => '1102878',
'home' => '/sdf/home/o/osgcms01',
'shell' => '/bin/bash',
},
osgatlas01: {
'username' => 'osgatlas01',
'comment' => 'OSG account for /atlas/Role=production',
'uid' => '1102872',
'home' => '/sdf/home/o/osgatlas01',
'shell' => '/sbin/nologin',
},
osgatlas02: {
'username' => 'osgatlas02',
'comment' => 'OSG account for /atlas/Role=software',
'uid' => '1102873',
'home' => '/sdf/home/o/osgatlas02',
'shell' => '/sbin/nologin',
},
osgatlas03: {
'username' => 'osgatlas03',
'comment' => 'OSG account for /atlas/usatlas',
'uid' => '1102874',
'home' => '/sdf/home/o/osgatlas03',
'shell' => '/sbin/nologin',
},
osgatlas04: {
'username' => 'osgatlas04',
'comment' => 'OSG account for /atlas',
'uid' => '1102875',
'home' => '/sdf/home/o/osgatlas04',
'shell' => '/sbin/nologin',
},
osgldmx01: {
'username' => 'osgldmx01',
'comment' => 'OSG accont for LDMX experiment',
'uid' => '1102884',
'home' => '/sdf/home/o/osgldmx01',
'shell' => '/bin/bash',
},
},
}

Recipe:

remove each user in attributes/default.rb

node['localusers']['osg']['remove'].each do |removeuser|
user removeuser do
action :remove
end
end

add each user in attributes/default.rb

node['localusers']['osg']['add'].each do |_k, v|
user v['username'] do
comment v['comment']
uid v['uid']
home v['home']
shell v['shell']
gid 'OG'
manage_home false
action [:create, :lock]

only_if { ::Dir.exist?('/sdf/home/o') }

only_if { ::File.writable?('/sdf/home') }

end
end