Debian 12 bookworm
Sponsored Link

Puppet : How to use [user Resource]2023/08/10

 

This is the examples for [user] resource.

[1] It manages the configuration to keep [bookworm] user exists.
# generate encrypted password for a user

root@dlp:~#
python3 -c 'import crypt,getpass; \
print(crypt.crypt(getpass.getpass(), \
crypt.mksalt(crypt.METHOD_SHA512)))'

Password:
$6$Fb2fpm8Vctsxxxxxxxxxx
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
user { 'bookworm':
  ensure     => present,
  home       => '/home/bookworm',
  managehome => true,
  password   => '$6$0XTc2rjlxxxxxxxx',
}
[2] Specify UID or GID of a group explicitly.
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
group { 'bookworm':
  ensure => present,
  gid    => 2001,
}
user { 'bookworm':
  ensure     => present,
  home       => '/home/bookworm',
  managehome => true,
  uid        => 2001,
  gid        => 2001,
  groups     => ['bookworm', 'adm'],
  password   => '$6$0XTc2rjlxxxxxxxx',
}
[3] Specify maxage or minage of password and comment explicitly.
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
group { 'bookworm':
  ensure => present,
  gid    => 2001,
}
user { 'bookworm':
  ensure     => present,
  home       => '/home/bookworm',
  managehome => true,
  uid        => 2001,
  gid        => 2001,
  groups     => ['bookworm', 'adm'],
  password   => '$6$0XTc2rjlxxxxxxxx',
  password_max_age => 90,
  password_min_age => 1,
  comment          => 'Bookworm User',
}
[4] It manages the configuration to keep [bookworm] user does not exist. (If exists, it is deleted included home directory.)
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
user { 'bookworm':
  ensure     => absent,
  home       => '/home/bookworm',
  managehome => true,
}
Matched Content