Ask Your Question
0

Is it possible to have file resource name value as an array [closed]

asked 2017-04-18 07:17:27 -0500

Hello,

I want to set file ressource like that :

classe llibrenms::agent {

$scripts = ['dpkg','bind'] file {"/usr/lib/checkmkagent/local/${scripts}": source => "/opt/librenms-agent/agent-local/${scripts}", }

But it gave me :

Failed to apply catalog: Parameter source failed on File[/usr/lib/checkmkagent/local/[dpkg, bind]]: Failed to convert '/opt/librenms-agent/agent-local/[dpkg, bind]' to URI: bad component(expected absolute path component): /opt/librenms-agent/agent-local/[dpkg,%20bind] at /etc/puppetlabs/code/environments/production/modules/snmp/manifests/init.pp:126

What can I do to resolve this ?

Thank you !

}

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ndevouge
close date 2017-04-20 04:33:47.483164

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-04-20 03:42:53 -0500

fvoges gravatar image

When you use an array for the title, you can not use variable interpolation. And all the attributes need to be the same for all the resources declared using the array.

In Puppet 4, you can use code like this to do what you want:

$scripts = ['dpkg','bind']
$scripts.each | String $script | {
  file { "/usr/lib/checkmkagent/local/${script}":
    ensure => file,
    source => "/opt/librenms-agent/agent-local/${script}", 
  }
}
edit flag offensive delete link more

Comments

In puppet 3, you were able to use the https://forge.puppet.com/puppetlabs/stdlib#prefixhttps://forge.puppet.com/puppetlabs/stdlib#suffix methods to achieve something similar

DarylW gravatar imageDarylW ( 2017-04-21 10:22:29 -0500 )edit
0

answered 2017-04-20 04:33:24 -0500

Wow perfect ! Thank you for your response, it works perfectly :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-04-18 07:17:27 -0500

Seen: 21 times

Last updated: Apr 20