Windows execute resource, not_if and exit code 42


#1

Hi chefs,

I’ve been putting off the upgrade to 0.10 for a while now because things
broke horribly when I first tried 0.10 on Windows. Trying 0.10.6-beta2,
things seem to have changed for the worse - I can’t even complete a Chef run
now…

It appears that Windows commands executed with ShellOut are regularly
returning exit code 42 on success. I can work around this for the main
"execute" blocks by specifying the return code, but for those protected with
"not_if", commands get run that shouldn’t be as the check performed is
exit_code!=0. For example, the following old block is near the top of my
run list (I realise that this could be replaced with a user block):

execute “net user chef /ADD /MOREHERE” do

not_if “net user chef”

end

What happens is:

DEBUG: Executing net user chef

DEBUG: STDOUT:

DEBUG: Ran net user chef returned 42

<the net user chef /ADD /MOREHERE" command then gets run>

When I run “net user chef” manually, I get return code 0.

If I use chef 0.9.18, this works without any problems. With 0.10.0, chef
ran ok but I had some problems with search results appearing and vanishing a
few seconds later on the server.

Is there a way to use “not_if” in a straightforward fashion in Windows?

Dan.


#2

On Tuesday, November 8, 2011 at 8:40 AM, Daniel Oliver wrote:

Hi chefs,

It appears that Windows commands executed with ShellOut are regularly returning exit code 42 on success. I can work around this for the main “execute” blocks by specifying the return code, but for those protected with “not_if”, commands get run that shouldn’t be as the check performed is exit_code!=0. For example, the following old block is near the top of my run list (I realise that this could be replaced with a user block):

not_if and only_if actually use the older popen4 code (which we’re slowly phasing out) to run commands. I’m not aware of any windows-related changes to this code since 0.9.x. Regardless, I’ll look into fixing this for a new beta release.

execute resources do, however, use ShellOut. Are you experiencing this problem with execute resources in the 0.10.6 beta?

Dan DeLeo


#3

I did at one point have a problem with the following returning code 42 at one point, but I can’t reproduce it after a night’s sleep. It may have been before I tried upgrading to Ruby 1.9.2 from 1.8.7, although rolling back doesn’t cause it to occur either.

execute ‘ipconfig /flushdns’ do
only_if { resources(‘template[/etc/hosts]’).updated? }
end

Dan.

-----Original Message-----
From: Daniel DeLeo [mailto:ddeleo@kallistec.com] On Behalf Of Daniel DeLeo
Sent: 09 November 2011 08:02
To: chef@lists.opscode.com
Subject: [chef] Re: Windows execute resource, not_if and exit code 42

On Tuesday, November 8, 2011 at 8:40 AM, Daniel Oliver wrote:

Hi chefs,

It appears that Windows commands executed with ShellOut are regularly returning exit code 42 on success. I can work around this for the main “execute” blocks by specifying the return code, but for those protected with “not_if”, commands get run that shouldn’t be as the check performed is exit_code!=0. For example, the following old block is near the top of my run list (I realise that this could be replaced with a user block):

not_if and only_if actually use the older popen4 code (which we’re slowly phasing out) to run commands. I’m not aware of any windows-related changes to this code since 0.9.x. Regardless, I’ll look into fixing this for a new beta release.

execute resources do, however, use ShellOut. Are you experiencing this problem with execute resources in the 0.10.6 beta?

Dan DeLeo