I use a version of this:
In a quest to make it easier for myself and others to modify my Chef recipes, I thought it was
Est. reading time: 2 minutes
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