| Puppet Version: 6/7 ** I wasn't sure where to file this, but I encountered some unexpected behaviour today. Given the following puppet code
$array = [ 'one', 'two', 'three'] |
|
notice( |
{ |
'foo' => $array, |
'bar' => $array, |
'foobar' => $array, |
}.to_yaml |
) |
|
# These `flatten`s look superfluous, but aren't |
|
notice( |
{ |
'foo' => $array.flatten, |
'bar' => $array.flatten, |
'foobar' => $array.flatten, |
}.to_yaml |
) |
I'd expect to notice the same YAML being output. Instead, in the version where I don't, (seemingly randomly call `flatten`), I get yaml with anchors (which I happen not to like). ie
❯ puppet apply -t test.pp |
Info: Loading facts |
Notice: Scope(Class[main]): --- |
foo: &1 |
- one |
- two |
- three |
bar: *1 |
foobar: *1 |
|
Notice: Scope(Class[main]): --- |
foo: |
- one |
- two |
- three |
bar: |
- one |
- two |
- three |
foobar: |
- one |
- two |
- three
|
Whilst I understand that there's an issue with values being passed to the to_yaml function by reference and `flatten` gets around this by creating 3 new objects, I don't feel this meets the https://en.wikipedia.org/wiki/Principle_of_least_astonishment test. I don't think it's documented anywhere that puppet variables can act this way with functions. |