3

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!

rvs
  • 4,125
  • 1
  • 27
  • 31

3 Answers3

6

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"
}
freiheit
  • 14,544
  • 1
  • 47
  • 69
NoNoNo
  • 1,963
  • 14
  • 20
2

works for me perfect this..

define hardlink($source=$name, $target) {                                                                                                                      
    exec {                                                                                                                                                   
        "hardlink-$name":                                                                                                                                    
            command => "ln -P --force $source $target",                                                                                                         
            path    => "/usr/bin:/bin",                                                                                                                      
            unless  => "test $source -ef $target";                                                                                                           
    }                                                                                                                                                        
}
pcaceres
  • 129
  • 1
  • 5
1

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",
  }
jag3773
  • 21
  • 2