Ask Your Question

Puppet variables are really constants?

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

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

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

DarylW gravatar image

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

There are some differences between 'constant' and 'variable' in different languages, for example in java -

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


Asked: 2017-01-15 12:27:02 -0600

Seen: 135 times

Last updated: Jan 16 '17