Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Last active August 29, 2015 13:58
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 hlindberg/9975348 to your computer and use it in GitHub Desktop.
Save hlindberg/9975348 to your computer and use it in GitHub Desktop.
ducks in a row - puppet
define duck($name) {
notice "duck $name"
include c
}
class c {
notice 'in c'
duck { 'duck0': name => 'mc scrooge' }
}
class a {
notice 'in a'
duck {'duck1': name => 'donald' }
include b
duck {'duck2': name => 'daisy' }
}
class b {
notice 'in b'
duck {'duck3': name => 'huey' }
duck {'duck4': name => 'dewey' }
duck {'duck5': name => 'louie' }
}
include a
@hlindberg
Copy link
Author

What does this print out?

@hlindberg
Copy link
Author

Answer:

Notice: Scope(Class[A]): in a
Notice: Scope(Class[B]): in b
Notice: Scope(Duck[duck1]): duck donald
Notice: Scope(Class[C]): in c
Notice: Scope(Duck[duck3]): duck huey
Notice: Scope(Duck[duck4]): duck dewey
Notice: Scope(Duck[duck5]): duck louie
Notice: Scope(Duck[duck2]): duck daisy
Notice: Scope(Duck[duck0]): duck mc scrooge

@hlindberg
Copy link
Author

why is mc scrooge at the end?

@zaphod42
Copy link

zaphod42 commented Apr 4, 2014

mc scrooge is at the end because it is pushed onto the end of the FIFO queue to process defines. Because a and b are classes the creation of their duck resources is evaluated as soon as it evaluates the include statements inside the classes. However, mc scrooge isn't enqueued until the first duck is evaluated, which is after the a and b classes. This means that it goes to the end of the queue and so will show up last.

@zaphod42
Copy link

zaphod42 commented Apr 4, 2014

"the creation of their duck resources is evaluated as soon as it evaluates the include statements". To clarify, it is the creation of the resources that is done immediately, but not the evaluation of their bodies.

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