ptierno / puppet-windowspagefile

Puppet type and provider to manage windows pagefiles
Other
1 stars 5 forks source link

Windows 2012R2 - undefined method 'InitialSize=' for nil:NilClass #3

Closed snootched closed 9 years ago

snootched commented 9 years ago

Running module on Windows 2012 R2 generates 'undefined method' error.

Module version: mod 'ptierno/windowspagefile', '1.2.2'

Attemtping code:

class profiles::common::win::pagefile {
  pagefile { 'c:\pagefile.sys':
    initialsize => 200,
    maximumsize => 1024,
 }

  pagefile { 'u:\pagefile.sys':
    systemmanaged => true,
  }

}

PS C:\temp> puppet resource pagefile
pagefile { 'c:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '200',
  maximumsize   => '1024',
  systemmanaged => 'false',
}

pagefile { 'u:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '0',
  maximumsize   => '0',
  systemmanaged => 'true',
}

Error observed:

Error: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 5:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Error: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 5:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Wrapped exception:
undefined method `InitialSize=' for nil:NilClass
Error: /Stage[main]/Profiles::Common::Win::Pagefile/Pagefile[c:\pagefile.sys]/ensure: change from absent to present failed: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 5:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Error: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 9:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Error: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 9:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Wrapped exception:
undefined method `InitialSize=' for nil:NilClass
Error: /Stage[main]/Profiles::Common::Win::Pagefile/Pagefile[u:\pagefile.sys]/ensure: change from absent to present failed: Could not set 'present' on ensure: undefined method `InitialSize=' for nil:NilClass at 9:/etc/puppetlabs/puppet/environments/production/modules/profiles/manifests/common/win/pagefile.pp
Notice: Finished catalog run in 7.03 seconds
ptierno commented 9 years ago

Thank you for reporting this. When I have some free time I will try to duplicate these errors and work on a solution.

ptierno commented 9 years ago

@snootched

So far I am unable to duplicate this issue. Applying the following to a newly provisioned Windows 2012 R2 box results in a successful puppet run.

pagefile { 'c:\pagefile.sys':
  initialsize        => 200,
  maximumsize => 1024
}
pagefile { 'u:\pagefile.sys':
  systemmanaged => true
}

After successful puppet run:

PS C:\Program Files\Puppet Labs\Puppet Enterprise\bin> puppet resource pagefile
pagefile { 'C:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '200',
  maximumsize   => '1024',
  systemmanaged => 'false',
}
pagefile { 'U:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '0',
  maximumsize   => '0',
  systemmanaged => 'true',
}

Are using open source puppet or puppet enterprise? If you are using open source, what version of ruby are you running?

I have had similar issues on 2012 R2 before releasing version 1.2.2 where win32ole was returning lowercase drive letters when looking for existing page files while the puppet type was munging the path parameter to a capitalized drive letter. This was fixed in release 1.2.2 by downcasing the path parameter in the type based off of the operatingsystemrelease fact.

snootched commented 9 years ago

@ptierno Thanks for looking into this. We are running Puppet Enterprise 3.7.2 I wonder if this is a case issue on the drive letter. After your successful run - I see your drive letters are uppercase when running "puppet resource pagefile" however, when I run that command, the drive letters are lower-case (mind you, the puppet agent didn't do a succesful run.)

ptierno commented 9 years ago

@snootched That is strange. When I have time I'm going to install a fresh 2012 R2. I've been testing with a cloud image. Let me see if there is a difference. The case of the drive letters seem to be the issue here although im not sure why. I'll get back to you.

ptierno commented 9 years ago

@snootched Still experiencing this issue? I am still unable to reproduce

velocity303 commented 9 years ago

Just commenting as I myself have just ran into this issue as well. If it helps, I also get a lowercase letter returned when issuing the puppet resource command on Server 2012 R2.

velocity303 commented 9 years ago

I was actually able to get around the issue and everything worked normally after manually changing the pagefile to be system managed before an additional puppet run. This may be an issue that occurs due to how the pagefile was previously set.

For reference my initial page file was set as follows:

Custom Size: initial size 512MB maximum size 512MB Selected Drive C:

Automatically manage paging file size for all drives was disabled.

Hope this helps!

ptierno commented 9 years ago

@velocity303 @snootched I believe II have found the issue. A commit should be coming shortly after doing some testing.

TheCraiggers commented 9 years ago

For what it's worth, I'm also running into this issue with Puppet Enterprise 3.8 with a pp similar to @snootched.

I know you said you believe you already found the issue, but let me know if I can do anything to help diagnose / test.

ptierno commented 9 years ago

@TheCraiggers apologies for the delay. I have been strapped on time. I will try to get a commit in between today and tomorrow on a new branch for you to test.

ptierno commented 9 years ago

@TheCraiggers @snootched @velocity303

Please test now against the github_issue_3 branch

TheCraiggers commented 9 years ago

Thanks a ton for looking into this for us, and for writing this module in the first place.

Well, the good news is it looks to have fixed the errors I was seeing. The bad news is the test I was attempting to do is still failing.

I'm attempting to add a new pagefile on another drive, and remove the default one on C:. So I have a init.pp that looks like this:

            #Remove pagefile from the C drive
            pagefile { 'c:\pagefile.sys':
                ensure => absent,
            }

            #Add pagefile to the E drive
            pagefile { 'e:\pagefile.sys':
                ensure => present,
                systemmanaged => true,
            }

It seems to add the pagefile just fine to the E drive, but it's not removing the pagefile from C. At least not consistently.

I noticed the following in the ruby code (I'm by no means a ruby expert though) which looks to be hard coding the pagefile to be 'present'. Is this intended? Should I be attempting to go about this a different way? Should I open a new issue?

new(
    :name          => pagefile.Name,
    :ensure        => :present,
    :initialsize   => pagefile.InitialSize,
    :maximumsize   => pagefile.MaximumSize,
    :systemmanaged => system_managed
  )
ptierno commented 9 years ago

@TheCraiggers that code is part of the self.instances method which is used by the puppet resource command, shouldn't have much to do with a puppet run. This issue may be related to how i handled ensure => absent. I think it turns on windows automatic managed pagefile setting. can you give me the output of puppet resource pagefile from your windows machine?

Thanks

TheCraiggers commented 9 years ago
pagefile { 'C:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '0',
  maximumsize   => '0',
  systemmanaged => 'true',
}
pagefile { 'e:\pagefile.sys':
  ensure        => 'present',
  initialsize   => '0',
  maximumsize   => '0',
  systemmanaged => 'true',
}

Interesting it thinks the C pagefile needs to be present. I presume that's what you were talking about.

ptierno commented 9 years ago

@TheCraiggers thats because the 'automatically managed' setting was enabled. I'm going to mark this issue as closed. Can you create a new issue regarding this and I will work to add the expected functionality to ensure, or at least create a new parameter on how absent should work, either restore the default windows automatic management, or completely remove.