木偶复制目录,但不是其内容

时间:2017-10-24 10:35:33

标签: recursion copy puppet

我想在我的节点上管理文件/home/user_name/scripts/file0/home/user_name/scripts/file1,...作为主文件上具有相同路径的文件的副本。

依赖/home/user_name出现在每个节点上,我把它放在清单中:

file { '/home/user_name/scripts':
  ensure  => 'directory',
  path    => '/home/user_name/scripts',
  recurse => true
}

确实会在每个节点上创建目录,但不会复制内容file0file1,...

我尝试添加source参数,还添加了recurse=>remote,但没有取得进一步的成功。

更新:尝试添加source参数,我补充道:

file { '/home/user_name/scripts':
  ensure  => 'directory',
  path    => '/home/user_name/scripts',
  recurse => true,
  source  => '/home/user_name/scripts'
}

但没有成功。顺便说一句,这是运行puppet apply

时的输出
Notice: Compiled catalog for puppet, master_dns in environment production in 0.64 seconds
Notice: /Stage[main]/Exec_script/Exec[add_archi]/returns: executed successfully
Notice: Applied catalog in 2.60 seconds

2 个答案:

答案 0 :(得分:2)

@MattSchuchard已经向你指出the relevant documentation。他们解释说Puppet支持source参数形式的四种替代方案,并且您尝试使用的表单依赖于本地文件作为要管理的文件的来源。也就是说,正在配置节点的本地。

如果您想使用驻留在主服务器上的文件作为源,并且客户端无法直接访问它们(例如通过网络文件系统),那么您只剩下两个选择:使用{{1 }或puppet:方案。除非您想在主服务器上运行HTTP服务器,否则只有http: URI才是可行的选择。

但是,默认情况下,Puppet的文件服务器仅从模块中提供文件,而不是从任意路径提供文件。为什么你希望从主文件系统提供任意文件?什么是灾难的秘诀。为什么普通用户还需要主服务器上的主目录呢?

最好的解决方案是将目录树放在puppet:资源出现的任何模块中 - 比如mymodule / files / user_name / scripts。然后你可以这样编写你的资源:

file

但如果你坚持,你应该能够将源文件保留在现在的位置,并使用符号链接将其修补:

file { '/home/user_name/scripts':
  ensure  => 'directory',
  recurse => true,
  source  => 'puppet://modules/mymodule/user_name/scripts'
}

......和......

mymodule/files/user_name-scripts -> /home/user_name/scripts

答案 1 :(得分:1)

如果您希望Puppet复制文件,您需要告诉它应该复制文件的位置来自提供来源属性:

file {'/my/path':
    ensure  => 'directory',
    path    => '/my/path',
    recurse => true,
    source  => '/home/user_name/scripts',
    }

这将创建一个目录 / my / path 并以递归方式将所有文件和目录从节点的本地目录 / home / user_name / scripts 复制到 / my /路径