Ask Your Question
0

foreach loop Hiera Array

asked 2015-10-23 08:48:43 -0500

stefanoblitz gravatar image

Hello,

I am running puppet 3.7.5

I am trying to accomplish installing a bunch of features on Vista/Server 2008 R1.

The way I have done this is to create an array of features in Hiera and use the following code;

 Class blah_blah {
    $windowsfeatures = [hiera_array('windows::features')]
    if ($::operatingsystemmajrelease == 'Vista') or ($::operatingsystemmajrelease == '2008'){
      exec { "ocsetup.exe":
        command => "C:\Windows\System32\ocsetup.exe ${windowsfeatures}",
    }
   else {case statement using DISM for other OSs} 
}

The issue i have is that this command sees the array as one long string e.g SNMPTelnetSimpleTCP etc.

I need to separate these values somehow. My idea was to do a for loop through the array...Not so simple.

Any suggestions welcome :)

Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-23 14:16:18 -0500

lupin gravatar image

You can use a define type resource to iterate on your array.

class baz {
  $features = hiera_array('wfeatures')

  define foo {
    notify { "Calling feature ${name}": }
  }

  if $::operatingsystem == 'Centos' {
    foo { $features: }
  }

}



[root@localhost modules]# puppet apply lookup.pp 
Notice: Compiled catalog for localhost in environment production in 0.08 seconds
Notice: Calling feature bluescreen
Notice: /Stage[main]/Baz/Baz::Foo[bluescreen]/Notify[Calling feature bluescreen]/message: defined 'message' as 'Calling feature bluescreen'
Notice: Calling feature bloat
Notice: /Stage[main]/Baz/Baz::Foo[bloat]/Notify[Calling feature bloat]/message: defined 'message' as 'Calling feature bloat'
Notice: Calling feature viruses
Notice: /Stage[main]/Baz/Baz::Foo[viruses]/Notify[Calling feature viruses]/message: defined 'message' as 'Calling feature viruses'
Notice: Finished catalog run in 0.04 seconds
[root@localhost modules]# grep -A3 wfeatures /var/lib/hiera/defaults.yaml 
wfeatures:
  - viruses
  - bloat
  - bluescreen
edit flag offensive delete link more

Comments

I have used a define statement and it is now installing my features. The issue I now have is that it runs during every puppet run. I need to include an 'unless' or 'onlyif'. The way I was thinking of doing it was to run a query of installed features and then use that list to do an unless statement

stefanoblitz gravatar imagestefanoblitz ( 2015-10-26 04:30:12 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2015-10-23 08:48:43 -0500

Seen: 840 times

Last updated: Oct 23 '15