Ask Your Question
1

Puppet variables are really constants?

asked 2017-01-15 12:27:02 -0500

karthikeayan gravatar image

If a variable cannot be reassigned with different value then how can it be called as variables? Shouldn't it be called constants?

As I know Puppet's variables cannot be reassigned in the single scope.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-01-16 08:03:26 -0500

DarylW gravatar image

updated 2017-01-16 08:06:29 -0500

There are some differences between 'constant' and 'variable' in different languages, for example in java - http://stackoverflow.com/questions/50...

I would call puppet's variables Immutable, but the wording used by the official documentation is

No reassignment

Unlike most other languages, Puppet only allows a given variable to be assigned once within a given scope. You may not change the value of a variable, although you may assign a different value to the same variable name in a new scope:

By making the variables unable to be reassigned within the same scope, you fit more nicely in the declarative style that puppet is based around, and you help remove different classes of problems that can occur with variables that can be modified. Now that puppet4 has support for different functions that work on collections, it makes it much eaiser to work in a style where you either iterate, map, or reduce across a collection instead of reassigning variables. You also can gather up a collection of different variables and join them together instead of constantly appending the previous variable with an additional value.

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: 2017-01-15 12:27:02 -0500

Seen: 60 times

Last updated: Jan 16