Skip to content

Instantly share code, notes, and snippets.

@traylenator
Created June 21, 2012 14:19
Show Gist options
  • Save traylenator/2966012 to your computer and use it in GitHub Desktop.
Save traylenator/2966012 to your computer and use it in GitHub Desktop.
Create a block of pool accounts for grid with puppet.
#!/usr/bin/puppet apply
class {'grid_users':}
class grid_users {
#group { "cmsusr":
# ensure => present,
# gid => 4050
#}
#group { "cmssgm":
# ensure => present,
# gid => 4070
#}
userblock{ 'cmssgm':
startuid => 43590,
count => 9,
prefix => 'cmsusr',
group => 'cmsusr',
secondary => ['cmssgm','random']
}
}
define userblock ($prefix = $title, $count = 1, $startuid , $secondary = [], $group = $title ) {
$yaml = inline_template('
---
<% @count.to_i.times do |i| -%>
<%= @prefix %><%= i.to_s %>:
uid: <%= i + @count.to_i %>
gid: <%= @title %>
<% if @secondary.length >= 1 then -%>
groups:
<% @secondary.each do |grp| -%>
<%= grp %>
<% end -%>
<% end -%>
<% end -%>
')
notice($yaml)
$userdata = parseyaml($yaml)
create_resources(user,$userdata)
}
---
cmsusr0:
uid: 9
gid: cmssgm
groups:
cmssgm
random
cmsusr1:
uid: 10
gid: cmssgm
groups:
cmssgm
random
cmsusr2:
uid: 11
gid: cmssgm
groups:
cmssgm
random
cmsusr3:
uid: 12
gid: cmssgm
groups:
cmssgm
random
cmsusr4:
uid: 13
gid: cmssgm
groups:
cmssgm
random
cmsusr5:
uid: 14
gid: cmssgm
groups:
cmssgm
random
cmsusr6:
uid: 15
gid: cmssgm
groups:
cmssgm
random
cmsusr7:
uid: 16
gid: cmssgm
groups:
cmssgm
random
cmsusr8:
uid: 17
gid: cmssgm
groups:
cmssgm
random
@traylenator
Copy link
Author

would hopefully create cms22, cms23, .... cms34

@gmccance
Copy link

Cool... might want a %03d formatter in there.

@traylenator
Copy link
Author

Fantastic, you use inline_template to represent the hash of user data as yaml and then parseyaml to
convert to a hash before feeding the whole lot to create_resources.

Job done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment