将符号链接的内容复制到目录

时间:2018-05-11 18:23:12

标签: puppet

我正在尝试将symlink目录的内容复制到Windows上的普通目录:

file { "copy symlink contents to directory":
    ensure             => directory,
    path               => "C:/Users/devacct/Desktop/puppet/puppet_dir2/", #directory
    source             => "C:/Users/devacct/Desktop/puppet/filessym/", #symlink
    recurse            => true,
    source_permissions => ignore,
    links              => 'manage',
    #ignore             => $ignore_files,
    #purge              => $purge,
    force              => true,
}

此操作失败并显示错误消息:

Error: /Stage[main]/Custom::Profile::Symlink/File[copy symlink contents to directory]: Could not evaluate: Could not retrieve information from environment production source(s) file:/C:/Users/devacct/Desktop/puppet/filessym

将符号链接路径作为源属性的值提供是否有效?如果没有,我如何实现目标?

2 个答案:

答案 0 :(得分:1)

使用link块上的file属性follow

另外,设置没有最后反斜杠的源代码......试一试。

file { "copy symlink contents to directory":
    ensure             => directory,
    path               => "C:/Users/devacct/Desktop/puppet/puppet_dir2/", #directory
    source             => "C:/Users/devacct/Desktop/puppet/filessym", #symlink
    recurse            => true,
    source_permissions => ignore,
    links              => 'follow',
    #ignore             => $ignore_files,
    #purge              => $purge,
    force              => true,
}

答案 1 :(得分:0)

是的,通常使用符号链接作为源参数是有效的,并且如Kelson Silva所述,您还需要使用links => follow而不是links => manage(请参阅docs })。

我不知道你为什么会收到该错误信息。

FWIW,我在Mac OS X上测试了以下内容:

设置:

$ ls -ld /tmp/symlink
lrwxr-xr-x  1 alexharvey  wheel  10 12 May 16:31 /tmp/symlink@ -> realsource
$ ls -lL /tmp/symlink
total 0
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 a/
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 b/
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 c/
$ find /tmp/symlink/
/tmp/symlink/
/tmp/symlink//a
/tmp/symlink//a/f
/tmp/symlink//a/d
/tmp/symlink//a/d/somefile
/tmp/symlink//a/e
/tmp/symlink//c
/tmp/symlink//c/f
/tmp/symlink//c/d
/tmp/symlink//c/e
/tmp/symlink//b
/tmp/symlink//b/f
/tmp/symlink//b/d
/tmp/symlink//b/e

代码:

file { '/tmp/dest':
  ensure             => directory,
  links              => follow,
  source             => '/tmp/symlink',
  recurse            => true,
  source_permissions => ignore,
  force              => true,
}

结果:

Notice: Compiled catalog for harveya-c02vj38lhtd7-ume.local in environment production in 0.03 seconds
Notice: /Stage[main]/Test/File[/tmp/dest]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/d/somefile]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Test/File[/tmp/dest/a/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/f]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/f]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/f]/ensure: created
Notice: Applied catalog in 0.13 seconds