Hello, I'm attempting to use the reduce function(https://puppet.com/docs/puppet/6.2/function.html#reduce) to consolidate hiera facts into data structures I can use with puppet resources. I've run into an issue that I'm not sure how to solve. When the data passed to the reduce function results in 2 or more iterations, I get the data return I expect. When the data passed only results in 1 iterations, I get back no results when I expect one result. Here is the applicable code snippet (hiera lookups replaced with dummy data): ~~~ $groups = { "group1" => { "gid" => 901, "members" => ["user1","user2","user3","user4"], }, "group2" => { "gid" => 902, "members" => ["user2"], } } $hostgroups = [ "group1", "group2" ] $usernames = ["user1","user2"]
$usernames.each |$username| { $usergroups = $hostgroups.reduce([]) |$result, $group| { $members = $groups[$group]["members"] warning("[$username] $group: $members") if ( $username in $members ) { warning("[$username] Added $group") $result + $group } } warning("[$username] groups: $usergroups") warning() } ~~~ The output of this code shows user1 with an empty array of groups when it should have group1 while user2 has the expected 2 group output: ~~~ Warning: Scope(Class[Base::Test]): [user1] group1: [user1, user2, user3, user4] Warning: Scope(Class[Base::Test]): [user1] Added group1 Warning: Scope(Class[Base::Test]): [user1] group2: [user2] Warning: Scope(Class[Base::Test]): [user1] groups: Warning: Scope(Class[Base::Test]): Warning: Scope(Class[Base::Test]): [user2] group1: [user1, user2, user3, user4] Warning: Scope(Class[Base::Test]): [user2] Added group1 Warning: Scope(Class[Base::Test]): [user2] group2: [user2] Warning: Scope(Class[Base::Test]): [user2] Added group2 Warning: Scope(Class[Base::Test]): [user2] groups: [group1, group2] Warning: Scope(Class[Base::Test]): ~~~ Let me know if I'm missing something otherwise this seems like it might be a bug. Thanks, -Dan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/bc076bfc-86b2-40c9-a07e-05a632909048%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.