Puppet 测试并删除一系列文件/文件夹 [英] Puppet test and remove an array of files/folders

查看:43
本文介绍了Puppet 测试并删除一系列文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以某种方式使以下代码工作,看来如果我不先测试文件/文件夹,我最终会遇到错误:

I'm looking to make the following code work somehow, it seems if i do not test the files/folders first I end up with the error:

错误:无法应用目录:参数路径失败文件[/opt/dynatrace-6.2]:文件路径必须是完全限定的,而不是'["/opt/dynatrace-6.2", "/opt/dynatrace-5.6.0","/opt/rh/httpd24/root/etc/httpd/conf.d/dtload.conf","/opt/rh/httpd24/root/etc/httpd/conf.d/01_dtagent.conf"]' 在newrelic.pp:35

Error: Failed to apply catalog: Parameter path failed on File[/opt/dynatrace-6.2]: File paths must be fully qualified, not '["/opt/dynatrace-6.2", "/opt/dynatrace-5.6.0", "/opt/rh/httpd24/root/etc/httpd/conf.d/dtload.conf", "/opt/rh/httpd24/root/etc/httpd/conf.d/01_dtagent.conf"]' at newrelic.pp:35

相关部分

$dtdeps = [
  "/opt/dynatrace-6.2",
  "/opt/dynatrace-5.6.0",
  "${httpd_root}/conf.d/dtload.conf",
  "${httpd_root}/conf.d/01_dtagent.conf",
]

exec { "check_presence":
  require => File[$dtdeps],
  command => '/bin/true',
  onlyif => "/usr/bin/test -e $dtdeps",
}

file { $dtdeps:
  require => Exec["check_presence"],
  path    => $dtdeps,
  ensure  => absent,
  recurse => true,
  purge   => true,
  force   => true,
} ## this is line 35 btw

exec { "stop_dt_agent":
  command => "PID=$(ps ax |grep dtwsagent |grep -v grep |awk '{print$1}') ; [ ! -z $PID ] && kill -9 $PID",
  provider => shell,
}

service { "httpd_restart" :
    ensure    => running,
    enable    => true,
    restart   => "/usr/sbin/apachectl configtest && /etc/init.d/httpd reload",
    subscribe => Package["httpd"],
}

推荐答案

你的代码看起来基本正确,但你的file资源太过分了:

Your code looks basically correct, but you went overboard with your file resources:

file { $dtdeps:
  require => Exec["check_presence"],
  path    => $dtdeps,
  ...

确实从你的数组中创建了所有的文件资源(因为你使用一个数组作为资源标题)但是每一个然后将尝试使用与 path 值相同的数组,没有意义.

This does create all the file resources from your array (since you use an array for the resource title) but each single one of them will then try to use the same array as the path value, which does not make sense.

TL;DR 删除 path 参数,它应该可以正常工作.

TL;DR remove the path parameter and it should Just Work.

这篇关于Puppet 测试并删除一系列文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆