Ubuntu 24.04
Sponsored Link

Puppet : How to use [user Resource]2024/07/25

 

This is the examples for [user] resource.

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

root@dlp:~#
echo "userpassword" | openssl passwd -6 -stdin

$6$9GoE2liT6.P.U/aS$44JDdwgw/vdf48gqhuff2Jkct3zn3oj75e/91i2Jy/RSciTZTa5QKo.FAwqew7Lk/lckWQ6QqNSScQWfTset71
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
user { 'noble':
  ensure     => present,
  home       => '/home/noble',
  managehome => true,
  password   => '$6$9GoE2liT6.P.U/a*****',
}
[2] Specify UID or GID of group explicitly.
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
group { 'noble':
  ensure => present,
  gid    => 2001,
}
user { 'noble':
  ensure     => present,
  home       => '/home/noble',
  managehome => true,
  uid        => 2001,
  gid        => 2001,
  groups     => ['noble', '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 { 'noble':
  ensure => present,
  gid    => 2001,
}
user { 'noble':
  ensure     => present,
  home       => '/home/noble',
  managehome => true,
  uid        => 2001,
  gid        => 2001,
  groups     => ['noble', 'adm'],
  password   => '$6$0XTc2rjlxxxxxxxx',
  password_max_age => 90,
  password_min_age => 1,
  comment          => 'noble User',
}
[4] It manages the configuration to keep [noble] user does not exist. (If exists, it is deleted included home directory.)
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/user01.pp
user { 'noble':
  ensure     => absent,
  home       => '/home/noble',
  managehome => true,
}
Matched Content