Skip to content

Instantly share code, notes, and snippets.

@alex-harvey-z3q
Created March 17, 2014 09:43
Show Gist options
  • Save alex-harvey-z3q/9596548 to your computer and use it in GitHub Desktop.
Save alex-harvey-z3q/9596548 to your computer and use it in GitHub Desktop.
Imagine our user from before:
class users {
user { 'elmo':
ensure => present,
shell => '/bin/zsh',
home => '/home/elmo',
}
file { '/home/elmo':
ensure => directory,
}
file { '/home/elmo/.profile':
ensure => file,
source => 'puppet:///modules/users/profile',
}
}
What if we want more users?
class users {
user { 'elmo':
ensure => present,
shell => '/bin/zsh',
home => '/home/elmo',
}
user { 'piggy':
ensure => present,
shell => '/bin/zsh',
home => '/home/piggy',
}
user { 'kermit':
ensure => present,
shell => '/bin/bash',
home => '/home/kermit',
}
file { '/home/elmo':
ensure => directory,
}
file { '/home/piggy':
ensure => directory,
}
file { '/home/kermit':
ensure => directory,
}
file { '/home/elmo/.profile':
ensure => file,
source => 'puppet:///modules/users/profile',
}
file { '/home/piggy/.profile':
ensure => file,
source => 'puppet:///modules/users/profile',
}
file { '/home/kermit/.profile':
ensure => file,
source => 'puppet:///modules/users/profile',
}
}
Show students how to collapse into:
define myuser (
#user = $name,
shell = '/bin/zsh',
) {
user { $name:
ensure => present,
shell => '/bin/zsh',
home => '/home/elmo',
}
file { "/home/$name":
ensure => directory,
}
file { "/home/${name}/.profile":
ensure => file,
source => 'puppet:///modules/users/profile',
}
}
class users {
myuser { 'elmo': }
myuser { 'piggy': }
myuser { 'kermit':
shell => '/bin/bash',
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment