A collection of task oriented solutions in Puppet

 

Managing Symlinks

Challenge

You want to create a symlink using puppet.

Solution

class symlinker {

  # preferred symlink syntax
  file { '/tmp/link-to-motd':
    ensure => 'link',
    target => '/etc/motd',
  }

  # older, less clear syntax
  file { '/tmp/link-to-motd':
    ensure => '/etc/motd',
  }

}

Explanation

Although it may seem slightly counter intuitive at first you create and manage symlinks through the file type. It's worth mentioning that the title (in this example /tmp/link-to-motd) is the name of the link to create and the filename given in ensure is the file to link to. If you get these two options the wrong way around then you'll probably need to start reading the filebucket section.

The second example, with the target defined in the ensure, is essentially deprecated and should not be used. This will be detected by puppet-lint and appear as [ensure_not_symlink_target] symlink target specified in ensure attr.

See also

  • puppet-lint (TODO)