Puppet - 如何将目录的内容移动到另一个现有目录?
Puppet - How do I move the contents of a directory to another existing directory?
我有一个包含 .data
个文件和 .config/.config.example
个文件的目录。我需要使用 puppet 将所有 .data
文件移动到系统上不同的现有目录。我认为我目前拥有的人偶代码不正确 - 我做错了什么?
file { 'Owasp .data files':
ensure => directory,
path => '/etc/nginx/',
source => '/usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
recurse => true,
ignore => ['*.conf', '*.conf.example'],
}
我希望这会将除 .conf
和 .conf.example
文件之外的所有内容复制到 /etc/nginx
。但是,我收到以下错误:
box: Error: Cannot alias File[Owasp .data files] to ["/etc/nginx"] at /vagrant/modules/nginx_test/manifests/test.pp:112; resource ["File", "/etc/nginx"] already declared at /usr/share/puppet/modules/nginx/manifests/config.pp:193
所以您的问题实际上是您在目录的其他地方声明了 file { '/etc/nginx': }
。您只需为每个目录声明一次该资源。这将解决您的错误。您也不能声明两个具有相同 path
参数的不同标题的文件资源,因为 Puppet 会测试该参数的资源唯一性。
关于您的具体问题,您可以在 source
参数中使用文件 URI:https://docs.puppet.com/puppet/latest/reference/type.html#file-attribute-source
所以对于你的情况,你会这样做:
file { 'Owasp .data files':
ensure => directory,
path => '/etc/nginx/',
source => 'file:///usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
recurse => true,
ignore => ['*.conf', '*.conf.example'],
}
我有一个包含 .data
个文件和 .config/.config.example
个文件的目录。我需要使用 puppet 将所有 .data
文件移动到系统上不同的现有目录。我认为我目前拥有的人偶代码不正确 - 我做错了什么?
file { 'Owasp .data files':
ensure => directory,
path => '/etc/nginx/',
source => '/usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
recurse => true,
ignore => ['*.conf', '*.conf.example'],
}
我希望这会将除 .conf
和 .conf.example
文件之外的所有内容复制到 /etc/nginx
。但是,我收到以下错误:
box: Error: Cannot alias File[Owasp .data files] to ["/etc/nginx"] at /vagrant/modules/nginx_test/manifests/test.pp:112; resource ["File", "/etc/nginx"] already declared at /usr/share/puppet/modules/nginx/manifests/config.pp:193
所以您的问题实际上是您在目录的其他地方声明了 file { '/etc/nginx': }
。您只需为每个目录声明一次该资源。这将解决您的错误。您也不能声明两个具有相同 path
参数的不同标题的文件资源,因为 Puppet 会测试该参数的资源唯一性。
关于您的具体问题,您可以在 source
参数中使用文件 URI:https://docs.puppet.com/puppet/latest/reference/type.html#file-attribute-source
所以对于你的情况,你会这样做:
file { 'Owasp .data files':
ensure => directory,
path => '/etc/nginx/',
source => 'file:///usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
recurse => true,
ignore => ['*.conf', '*.conf.example'],
}