Puppet - 将多个文件复制到目录

qui*_*tin 6 puppet

我想将一些文件从puppet:// urls复制到代理上的目录中。我不确定我是否在这里做错了什么,但似乎 puppet 不喜欢这样

  file { '/etc/nginx/conf.d':
    path         => '/etc/nginx/conf.d',
    ensure       => directory,
    require      => File['/etc/nginx/nginx.conf'],
    source       => ['puppet:///modules/nginx/app1.conf',
                     'puppet:///modules/nginx/app2.conf'],
    sourceselect => all,
  }
Run Code Online (Sandbox Code Playgroud)

这是我尝试运行代理时得到的结果

错误:无法将临时文件 /etc/nginx/conf.d.puppettmp_9046 重命名为 /etc/nginx/conf.d:是一个目录

如果我通过在模块中创建目录并将资源指向它们来稍微改变一下它的工作原理

  mkdir module/files/app1 module/files/app2
  mv module/files/app1.conf module/files/app1
  mv module/files/app2.conf module/files/app2
Run Code Online (Sandbox Code Playgroud)

新资源

  file { '/etc/nginx/conf.d':
    path         => '/etc/nginx/conf.d',
    ensure       => directory,
    require      => File['/etc/nginx/nginx.conf'],
    source       => ['puppet:///modules/nginx/app1',
                     'puppet:///modules/nginx/app2'],
    sourceselect => all,
    recurse      => true,
  }
Run Code Online (Sandbox Code Playgroud)

必须创建目录来复制单个文件列表似乎有点愚蠢。

编辑

我尝试在路径上添加一个尾部斜杠,但认为这是解决方案,我立即跳了起来。原因是我在节点定义中注释了我的nginx类声明。尝试它虽然我从上面得到同样的错误。

  file { '/etc/nginx/conf.d/':
    path         => '/etc/nginx/conf.d/',
    ensure       => directory,
    require      => File['/etc/nginx/nginx.conf'],
    source       => ['puppet:///modules/nginx/app1.conf',          
                     'puppet:///modules/nginx/app2.conf'],
    sourceselect => all,
  }
Run Code Online (Sandbox Code Playgroud)

Dan*_*ner 9

缺少目的地的尾随 /。

首先有几件事:

为什么要确保目录和内容(源参数)?制作两种资源,一种用于目录,另一种用于目录中的两个文件。

它会给你一个错误,因为你是将文件采购到目录中,而不是将文件采购到目录中。一个目录只能有一个目录作为源。

因此,您可以创建单独的定义,因为您只定义了两个要在目录中获取的文件。另一种是在module/files下创建一个目录并将文件放在那里。然后,当您进行源定义时,您指定的是目录而不是文件。

希望这可以帮助。你自己已经执行的执行。