Variables, facts & Facter
Node data and conditionals.
Facts are data about a node, gathered by Facter at the start of every run — OS family and version, network interfaces, memory, CPU, virtualization, custom facts you add. They are available as variables in your manifests, so you write portable code that branches on the node’s reality: install the right package name per OS, size a setting from real memory, behave differently in a container versus bare metal.
$ facter os.family memory.system.totalos.family => Debianmemory.system.total => 7.76 GiB# used in a manifest:$pkg = $facts['os']['family'] ? { 'Debian' => 'apache2', default => 'httpd' }package { $pkg: ensure => installed }
Variables and scope
Puppet variables are immutable within a scope — you assign once, you cannot reassign, which enforces declarative thinking (no accumulating state). They are typed (String, Integer, Array, Hash, and richer data types) and you should reference facts through the $facts hash for clarity. Combined with selectors, case statements, and conditionals, facts let one manifest correctly configure a diverse fleet.
case $facts['os']['family'] {'Debian': { $svc = 'ssh' }'RedHat': { $svc = 'sshd' }default: { fail("Unsupported OS: ${facts['os']['family']}") }}service { $svc: ensure => running, enable => true }