Ask Your Question
0

Test and remove array of folders?

asked 2015-12-08 12:54:36 -0500

updated 2015-12-08 13:25:38 -0500

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 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

The pertinent parts

$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"],
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-12-08 14:49:10 -0500

aharden gravatar image

Remove the path metaparameter from File[$dtdeps]. Passing the array into the file resource's title will auto-explode into a file resource per array item, and each resource's title will be passed to the path metaparameter since it's the namevar.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-08 12:54:36 -0500

Seen: 62 times

Last updated: Dec 08 '15