Skip to content

Instantly share code, notes, and snippets.

@andrewfraley
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewfraley/fee28eaa91002f73c249 to your computer and use it in GitHub Desktop.
Save andrewfraley/fee28eaa91002f73c249 to your computer and use it in GitHub Desktop.
Puppet loop scope
$letter = 'z'
$list = ['a', 'b', 'c']
$list.each |$item| {
if $item == 'b' {
$letter = 'b'
notify{"Letter: ${letter}": }
}
}
notify{"Letter: ${letter}": }
@ahpook
Copy link

ahpook commented Jun 22, 2015

A slight modification for illustration:

$letter = 'z'
$list = ['a', 'b', 'c']
$list.each |$item| {
  if $item == 'b' {
    $letter = 'b'
  }
  notify{"Letter ${item}: ${letter}": }
}

Produced:

[vagrant@glitched ~]$ puppet apply ./looptest.pp
Notice: Compiled catalog for glitched.vmlocal in environment production in 0.33 seconds
Notice: Letter a: z
Notice: /Stage[main]/Main/Notify[Letter a: z]/message: defined 'message' as 'Letter a: z'
Notice: Letter b: b
Notice: /Stage[main]/Main/Notify[Letter b: b]/message: defined 'message' as 'Letter b: b'
Notice: Letter c: z
Notice: /Stage[main]/Main/Notify[Letter c: z]/message: defined 'message' as 'Letter c: z'
Notice: Applied catalog in 0.01 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment