Ask Your Question

file link for a array

asked 2015-05-08 06:28:07 -0600

lgbff gravatar image

updated 2015-05-08 06:29:53 -0600

I need to set many softlink.

the values are stored in an array:

links = [ 'link1', link2', link3' ]

For each link must create a softlink

This is for neuer Versions of puppet:

$links.each |String $link| {
  file {"/usr/bin/$link":
    ensure => link,
    target => "/opt/$link",

But i Use puppet 3.6

Any Idea?

thx Karsten

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-08 11:34:29 -0600

assuming files already exist and you dont want to upgrade to a funky new version that can do loops, you could try something like:

[root@pclient manifests]# cat init.pp
class stulink {

  define doit {
  file { "/usr/bin/$title":
    ensure => link,
    target => "/opt/$title",
doit { [ "a", "b", "c", "d" ]: }

include stulink

[root@pclient manifests]# puppet apply ./init.pp
Notice: Compiled catalog for pclient in environment production in 0.06 seconds
Notice: /Stage[main]/Stulink/Stulink::Doit[a]/File[/usr/bin/a]/ensure: created
Notice: /Stage[main]/Stulink/Stulink::Doit[b]/File[/usr/bin/b]/ensure: created
Notice: /Stage[main]/Stulink/Stulink::Doit[d]/File[/usr/bin/d]/ensure: created
Notice: /Stage[main]/Stulink/Stulink::Doit[c]/File[/usr/bin/c]/ensure: created
Notice: Finished catalog run in 0.03 seconds
[root@pclient manifests]#

Seems to do what you want?

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


Asked: 2015-05-08 06:28:07 -0600

Seen: 261 times

Last updated: May 08 '15