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 {                                                                                                                                                   
        "hardlinkdir-$name":                                                                                                                                 
            command => "cp -r --link $target $source",                                                                                                       
            path    => "/usr/bin:/bin",                                                                                                                      
            creates => $source;                                                                                                                              
    }                                                                                                                                                        
}                                                                                                                                                            

define hardlink(source=$name, target) {                                                                                                                      
    exec {                                                                                                                                                   
        "hardlink-$name":                                                                                                                                    
            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!

link|improve this question

feedback

1 Answer

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"
}
link|improve this answer
Use creates instead of unless. – Daniel C. Sobral Feb 7 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 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 at 18:11
feedback

Your Answer

 
or
required, but never shown

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