Ask Your Question
0

Class with array as input parameter

asked 2015-10-08 09:30:02 -0500

drm509 gravatar image

I'm trying to traverse an array passed as input parameter to a puppet class.

This is the code I currently have:

class mess($paramArray)
{
exec {
  **$paramArray.foreach( $param => echo $param >> /path/configFile.conf) :**
  cwd => "/var/tmp/",
  path    => ["/usr/bin", "/usr/sbin"]
}
}

What is a way to iterate over an array parameter?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-10-08 13:04:17 -0500

lupin gravatar image

Are you running on version with native iteration support?

If yes, then you can

$paramArray.each | $item | { 
    exec { $item:
        command => <your_cmd>,
    } 
 }

else you need to use a define type.

define mess ( $item = $name, )
   {
   exec { $item:
      command => <your_cmd>,
    }
 }

supply the Arrays as parameter

mess { $paramArray : }
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-10-08 09:30:02 -0500

Seen: 592 times

Last updated: Oct 08 '15