ghoneycutt/puppet-module-pam — pull request #71 by treydock (2014-08-13 03:19:19+00:00)
Title: Fix order of access.conf entries when allowed_users is a Hash

In Ruby 1.8.7 the order of a Hash is "random" [1]. The only way to ensure consistent order of elements when iterating over a Hash is to sort by the keys then reference the value using `Hash[key]`. Example of RSpec test output before changing `templates/access.conf.erb`.

```
Failures:

1) pam::accesslogin access.conf with hash entry containing string values should contain allowed_users
Failure/Error: verify_contents(subject, 'access_conf', [
expected: ["+ : username1 : cron", "+ : username2 : tty0", "- : ALL : ALL"]
got: ["+ : username2 : tty0", "+ : username1 : cron", "- : ALL : ALL"] (using ==)
# ./spec/classes/accesslogin_spec.rb:92

2) pam::accesslogin access.conf with hash entries containing string, array and empty hash should contain allowed_users
Failure/Error: verify_contents(subject, 'access_conf', [
expected: ["+ : username : tty5", "+ : username1 : cron tty0", "+ : username2 : cron", "+ : username3 : tty0", "+ : username4 : ALL", "- : ALL : ALL"]
got: ["+ : username : tty5", "+ : username3 : tty0", "+ : username1 : cron tty0", "+ : username2 : cron", "+ : username4 : ALL", "- : ALL : ALL"] (using ==)
# ./spec/classes/accesslogin_spec.rb:150
```

I observed this issue in production when using a Hash defined in Hiera. Puppet kept changing the order of the "allow" entries in access.conf.

[1] : http://www.ruby-doc.org/core-1.8.7/Hash.html - "The order in which you traverse a hash by either key or value may seem arbitrary, and will generally not be in the insertion order."