Puppet User, Group, SSH Key, Cron, Exec, Mount and Other Core Resource Types

Puppet Training Course 26 min min read Updated: Nov 17, 2026 Intermediate
Puppet User, Group, SSH Key, Cron, Exec, Mount and Other Core Resource Types
Intermediate Topic 2 of 3

Users and Groups

puppet group { 'developers': ensure => present, gid => 3000, } user { 'alice': ensure => present, uid => 2001, gid => 'developers', # primary group groups => ['sudo', 'docker'], # secondary groups shell => '/bin/bash', home => '/home/alice', managehome => true, # create the home directory comment => 'Alice Smith', password => Sensitive('$6$salt$hash...'), # a hashed password, never plain text password_max_age => 90, require => Group['developers'], } user { 'olduser': ensure => absent, # remove (add managehome => true to delete the home) }
Passwords: The password attribute needs a hash such as SHA-512 (openssl passwd -6), not the clear text. Keep hashes in encrypted Hiera or a secret store, and wrap them in Sensitive. For most servers, prefer SSH keys with locked passwords.
User attributeMeaning
ensurepresent or absent, and role for Windows/AIX
uid, gidFixed IDs for consistency across servers
groups, membershipExtra groups, and minimum (add) or inclusive (exact list)
systemtrue creates a system account
expiryAccount expiry date
purge_ssh_keysRemove SSH keys not managed by Puppet

SSH Keys

puppet ssh_authorized_key { 'alice@laptop': ensure => present, user => 'alice', type => 'ssh-ed25519', key => 'AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyDataHere', options => ['no-port-forwarding'], } user { 'deploy': ensure => present, managehome => true, purge_ssh_keys => true, # only keys managed by Puppet stay }

Put the public key only, never the private key. The key is just the middle part of the line from id_ed25519.pub.

A Reusable Defined Type for Accounts

puppet define profile::account ( Integer $uid, Array[String] $groups = [], Array[Hash] $ssh_keys = [], String $shell = '/bin/bash', ) { user { $title: ensure => present, uid => $uid, groups => $groups, shell => $shell, managehome => true, purge_ssh_keys => true, } $ssh_keys.each |$k| { ssh_authorized_key { "${title}-${k['name']}": user => $title, type => $k['type'], key => $k['key'], } } } # Data-driven from Hiera lookup('profile::accounts', Hash, 'deep', {}).each |$name, $cfg| { profile::account { $name: * => $cfg } }

Cron Jobs

puppet cron { 'nightly-backup': ensure => present, command => '/usr/local/bin/backup.sh >> /var/log/backup.log 2>&1', user => 'root', hour => 2, minute => 30, weekday => '*', } cron { 'every-5-min-check': command => '/usr/local/bin/check.sh', minute => '*/5', } cron { 'monthly-report': command => '/usr/local/bin/report.sh', monthday => 1, hour => 6, minute => 0, } cron { 'old-job': ensure => absent, }

For modern Linux systems, many teams create systemd timers by managing unit files with the file resource (plus the systemd module), but cron is perfectly fine for simple jobs.

exec: Run a Command (Use Carefully)

exec runs a command. It is powerful but not idempotent by itself. You must tell Puppet when the command is needed, or it will run on every run.

AttributeMeaning
commandThe command. Use a full path or set path
pathDirectories to search, such as ['/bin','/usr/bin','/usr/local/bin']
createsRun only if this file does not exist
onlyifRun only if this command returns 0
unlessRun only if this command returns non-zero
refreshonlyRun only when notified by another resource
cwd, user, environmentWorking directory, user, and env variables
timeoutSeconds before giving up (default 300)
returnsAccepted exit codes (default 0)
logoutputon_failure, true: show command output
puppet # 1. creates: run once, until the file exists exec { 'extract-app': command => 'tar -xzf /tmp/app.tar.gz -C /opt', path => ['/bin', '/usr/bin'], creates => '/opt/app/bin/app', } # 2. unless: run only if the check fails exec { 'add-swap': command => '/sbin/mkswap /swapfile && /sbin/swapon /swapfile', unless => '/sbin/swapon --show | /bin/grep -q swapfile', } # 3. onlyif: run only if something is true exec { 'reload-firewall': command => 'firewall-cmd --reload', path => ['/usr/bin'], onlyif => 'systemctl is-active firewalld', } # 4. refreshonly: run when a file changes exec { 'rebuild-index': command => '/usr/local/bin/reindex.sh', refreshonly => true, subscribe => File['/etc/app/index.conf'], }
Last resort: Before you use exec, search for a resource type or Forge module that already does the job. If you must use exec, add creates, unless, onlyif or refreshonly, otherwise the command runs every 30 minutes.

Mounts and Filesystems

puppet file { '/data': ensure => directory, } mount { '/data': ensure => mounted, # in fstab and mounted now device => 'UUID=1234-ABCD', fstype => 'ext4', options => 'defaults,noatime', dump => 0, pass => 2, require => File['/data'], } mount { '/mnt/share': ensure => mounted, device => 'nfs.example.com:/exports/share', fstype => 'nfs', options => 'rw,hard,intr', }
Mount ensureEffect
definedOnly in fstab
mountedIn fstab and mounted
unmountedIn fstab, not mounted
absentRemoved from fstab and unmounted

Hosts, Kernel Settings and Others

puppet host { 'db.internal': ensure => present, ip => '10.0.2.15', host_aliases => ['db', 'database'], } # Kernel parameters: use the Forge module herculesteam/augeasproviders_sysctl (or write /etc/sysctl.d/) file { '/etc/sysctl.d/90-puppet.conf': ensure => file, content => "net.ipv4.ip_forward = 1\nvm.swappiness = 10\n", notify => Exec['sysctl-reload'], } exec { 'sysctl-reload': command => '/sbin/sysctl --system', refreshonly => true, }

Other Built-in Types Worth Knowing

TypePurpose
notifyPrint a message in the run log (a resource, different from the notify metaparameter)
scheduleLimit resources to time windows or a number of runs
filebucketBackup storage for changed files
tidyRemove old files by age or size
yumrepoDefine a YUM/DNF repository
selboolean, selmoduleSELinux settings
zfs, zpoolZFS management
k5login, sshkeyKerberos and SSH host keys
augeasEdit structured config files using Augeas lenses
puppet tidy { '/var/log/myapp': age => '14d', recurse => true, matches => '*.log', } yumrepo { 'internal': ensure => present, descr => 'Internal packages', baseurl => 'https://repo.example.com/el9/', gpgcheck => 1, gpgkey => 'https://repo.example.com/RPM-GPG-KEY', enabled => 1, } notify { "Running on ${facts['networking']['fqdn']}": }

See All Types

bash puppet describe --list # all resource types puppet describe user # attributes and help for one type puppet describe user --meta # include metaparameters

Practice Tasks

  1. Create the group developers and three users in it, with home directories
  2. Add an SSH public key for one user and check ~/.ssh/authorized_keys
  3. Make a cron job that appends a timestamp to a file every five minutes and check it works
  4. Write an exec that creates a file only once using creates, then run Puppet twice to see it skipped
  5. Mount a tmpfs at /mnt/ramdisk with Puppet and check with df -h

Conclusion

Core types manage accounts (user, group, ssh_authorized_key), schedules (cron), commands (exec) and storage (mount). Make every exec idempotent with creates, unless, onlyif or refreshonly.

Quick Summary: user+group+ssh key; cron; exec needs creates/unless/onlyif/refreshonly; mount ensure mounted; puppet describe.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators