voxpupuli / puppet-augeasproviders

Alternative Augeas-based providers for Puppet
http://augeasproviders.com/
Apache License 2.0
63 stars 46 forks source link

pam: Could not set 'present' on ensure: undefined method `each' for nil:NilClass if arguments is not define #100

Closed Feandil closed 10 years ago

Feandil commented 10 years ago

The following code breaks puppet:

    pam { 'include_password-auth':
      service  => 'sshd',
      type     => 'auth',
      module   => 'password-auth',
      control  => 'include',
      position => 'after last',
    }

Here is the error:

Error: Could not set 'present' on ensure: undefined method `each' for nil:NilClass at 98:/***.pp
/var/lib/puppet/lib/puppet/provider/pam/augeas.rb:106
/var/lib/puppet/lib/augeasproviders/provider.rb:701:in `call'
/var/lib/puppet/lib/augeasproviders/provider.rb:701:in `augopen_internal'
/var/lib/puppet/lib/augeasproviders/provider.rb:146:in `augopen!'
/var/lib/puppet/lib/augeasproviders/provider.rb:786:in `augopen!'
/var/lib/puppet/lib/augeasproviders/provider.rb:201:in `create'
/usr/lib/ruby/site_ruby/1.8/puppet/property/ensure.rb:16:in `set_present'
/usr/lib/ruby/site_ruby/1.8/puppet/property.rb:197:in `send'
/usr/lib/ruby/site_ruby/1.8/puppet/property.rb:197:in `call_valuemethod'
/usr/lib/ruby/site_ruby/1.8/puppet/property.rb:498:in `set'
.....

Adding a ''arguments => []'' works:

    pam { 'include_password-auth':
      service  => 'sshd',
      type     => 'auth',
      module   => 'password-auth',
      control  => 'include',
      position => 'after last',
      arguments => []
    }
kbolko commented 10 years ago

Similar code produces the same error for me as well:

  pam { 'Enable pam_tally2 on accounts':
    ensure    => present,
    service   => 'sshd',
    type      => 'account',
    control   => 'required',
    module    => 'pam_tally2.so',
  }

Adding an empty arguments string does seem to bypass the problem.

Interestingly I get a different error if I try and actually add arguments. Using the following code:

  pam { 'Set tally2 entry on auth':
    ensure    => present,
    service   => 'sshd',
    type      => 'auth',
    control   => 'required',
    module    => 'pam_tally2.so',
    arguments => ['onerr=fail', 'deny=5', 'unlock_time=3600'],
  }

Produces the following error:

Debug: Puppet::Type::Pam::ProviderAugeas: Save failure details:
/augeas/files/etc/pam.d/sshd/error/path = /files/etc/pam.d/sshd/12
/augeas/files/etc/pam.d/sshd/error/lens = /usr/share/augeas/lenses/dist/pam.aug:58.21-.51:
/augeas/files/etc/pam.d/sshd/error/message = Failed to match
    { /optional/ }?{ /type/ = /auth|session|account|password/ }{ /control/ = /\\[[^]\001-\004\n#]*\\]|[^\001-\004\t [][^\001-\004\t ]*/ }{ /module/ = /[^\001-\004\t\n #]+/ }{ /argument/ = /[^\001-\004\t\n #]+/ }*({ /#comment/ = /[^\001-\004\t\n\r ][^\001-\004\n]*[^\001-\004\t\n\r ]|[^\001-\004\t\n\r ]/ } | ())
  with tree
    { "type" = "auth" } { "control" = "required" } { "module" = "pam_tally2.so" } { "argument" = "onerr=fail deny=5 unlock_time=3600" }
Error: /Stage[main]/***::***/Pam[Set tally2 entry on auth]: Could not evaluate: Failed to save Augeas tree to file. See debug logs for details.

This is using the current Master branch as of a few hours ago and Puppet 3.6.1. If I can provide any further information please let me know.

Thank you.

raphink commented 10 years ago

Attached code should fix this issue.

kbolko commented 10 years ago

@raphink The attached code fixes does indeed fix the issue, thank you.