The trifecta: package, file, and service

Package, file, service: Learn it, live it, love it. Even if this is the only Puppet you know, you can get a lot done.

package { 'openssh-server':
  ensure => installed,
}

file { '/etc/ssh/sshd_config':
  source  => 'puppet:///modules/sshd/sshd_config',
  owner   => 'root',
  group   => 'root',
  mode    => '0640',
  notify  => Service['sshd'], # sshd restarts whenever you edit this file.
  require => Package['openssh-server'],
}

service { 'sshd':
  ensure     => running,
  enable     => true,
}

package

Manages software packages.

AttributeDescriptionNotes
nameThe name of the package, as known to your packaging system. Defaults to title.
ensureWhether the package should be installed, and what version to use. Allowed values:
  • present

  • latest (implies present)

  • Any version string (implies present)

  • absent

  • purged

    purged ensures absent, and deletes configuration files and dependencies, including those that other packages depend on. Provider-dependent.

sourceWhere to obtain the package, if your system’s packaging tools don’t use a repository. 
providerWhich packaging system to use (such as Yum or Rubygems), if a system has more than one available. 

file

Manages files, directories, and symlinks.

AttributeDescriptionNotes
ensureWhether the file should exist, and what it should be. Allowed values:
  • file

  • directory

  • link (symlink)

  • present (anything)

  • absent

pathThe full path to the file on disk.Defaults to title.
ownerBy name or UID. 
groupBy name or GID. 
modeMust be specified exactly. Does the right thing for directories. 
For normal files:

source Where to download contents for the file. Usually a puppet:/// URL.
content The file’s desired contents, as a string. Most useful when paired with templates, but you can also use the output of the file function.
For directories:
sourceWhere to download contents for the directory, when recurse => true.
recurseWhether to recursively manage files in the directory.
purgeWhether unmanaged files in the directory should be deleted, when recurse => true.
For symlinks:
targetThe symlink target. (Required when ensure => link.)
Other notable attributes:
  • backup

  • checksum

  • force

  • ignore

  • links

  • recurselimit

  • replace

service

Manages services running on the node. As with packages, some platforms have better tools than others, so read the relevant documentation before you begin.

You can make services restart whenever a file changes with the subscribe or notify metaparameters. For more info, see Relationships and ordering.

AttributeDescriptionNotes
nameThe name of the service to run.Defaults to title.
ensureThe desired status of the service. Allowed values:
  • running (or true)

  • stopped (or false)

enableWhether the service should start on boot. Doesn’t work on all systems. 
hasrestartWhether to use the init script’s restart command instead of stop+start. Defaults to false.
hasstatusWhether to use the init script’s status command. Defaults to true.
Other notable attributes:

If a service has a bad init script, you can work around it and manage almost anything using the status, start, stop, restart, pattern, and binary attributes.