Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there a way to define hardlinks inside puppet manifest?

It seems file type can only define symbolic links, but I need it to be hard links in order to make some of my chrooted applications to work. For example, I need to hardlink

/etc/hosts -> $chroot/etc/hosts
/etc/resolvf.com -> $chroot/etc/resolv.conf

and so on.

What can be the simplest way to archive that?

Update: thanks, I've ended with following defines:

define hardlinkdir(source=$name, target) {                                                                                                                   
    exec {                                                                                                                                                   
            command => "cp -r --link $target $source",                                                                                                       
            path    => "/usr/bin:/bin",                                                                                                                      
            creates => $source;                                                                                                                              

define hardlink(source=$name, target) {                                                                                                                      
    exec {                                                                                                                                                   
            command => "ln --force $target $source",                                                                                                         
            path    => "/usr/bin:/bin",                                                                                                                      
            unless  => "test $source -ef $target";                                                                                                           

Sure, they are not perfect, but they does the job and it's everything I need.

Thank you for your help!

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can use also the statement "exec" if you can't find any other way.

exec { "hardlink1":
    command => "ln target source",
    path    => "/usr/local/bin:/bin",
    creates => "yourhardlink"
share|improve this answer
Use creates instead of unless. –  Daniel C. Sobral Feb 7 '12 at 17:26
Hmm, I think unless can be better, I'll try to check if source & target are really same files. –  rvs Feb 7 '12 at 17:52
@rvs ls -i provides the inode number of the file as the first column. Two hard links pointing at the same file on the same filesystem will have the same inode number. You could write up a module to test that. –  Jeff Ferland Feb 7 '12 at 18:11
They should really support this on the file resource IMO. –  quickshiftin Feb 19 '14 at 21:08

It is also fairly trivial to just pipe out the same file to multiple locations with Puppet, as an example:

  file { [ "/etc/named.conf", "/var/named/chroot/etc/named.conf" ]:
    mode    => 640,
    owner   => root,
    group   => named,
    ensure  => present,
    require => [ Package['bind'], Package['bind-chroot'], ],
    source  => "puppet:///modules/named/named.conf",
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.