On Friday, July 20, 2012 2:58:15 AM UTC-5, Brett Maton wrote:
I'm trying to add elements to an array with the plusingment operator.
However the following results in
err: Could not retrieve catalog from remote server: Error 400 on SERVER:
Syntax error at '+>'; expected '}' at
/etc/puppet/modules/php/manifests/params.pp:17
(This isn't a question of whether or not php53 will be happy with
php-pecl-memcache, its about extending arrays).
class php::params {
case $osmajor {
'5': {
$phpService = 'php53'
$phpModules = [
'php-pecl-memcache',
]
}
default: {
$phpService = 'php'
$phpModules = [
'php-pecl-memcached',
]
}
}
$phpVersion = 'latest'
$phpModules +> [ "${phpService}-mysql",
"${phpService}-xml",
"${phpService}-mbstring",
"${phpService}-cli",
"${phpService}-gd",
"${phpService}-soap",
]
}
You can never, under any circumstances, by any means, change the value of a
Puppet variable once it is set. This is a Puppet invariant.
The plussignment operator gives the *illusion* of appending to an array
variable that belongs to a different scope, but would normally be visible
in the current scope as a result of dynamic scoping. It is best to think
of it as creating a new variable of the same name in the current scope,
with a value derived from the original one's as directed by the
plussignment.
Plussignment cannot be applied to a variable that has already been declared
in the current scope, either directly or by a different plussignment, on
account of the prohibition against changing existing variables' values.
Also, be aware that scoping in Puppet does not follow the same rules as it
does in many programming languages. Most blocks (delimited in Puppet by
curly braces, {}) do not establish new scopes. Aside from the global
scope, only class bodies, definition bodies, and node declarations
establish new scopes.
Because plussignment is inherently connected to dynamic scoping, and
dynamic scoping is deprecated, it would be best to find a different way to
do what you're trying to do.
John