- From: Carlos Camacho <
>
- To: "
" <
>
- Subject: [chef] Re: RE: RE: Re: Re: NOT_IF and ONLY_IF validation problem.
- Date: Thu, 21 Aug 2014 11:06:48 +0200
Adam!
Thanks a lot xD
https://www.youtube.com/watch?v=BNV2jZUjKlc
On Wed, Aug 20, 2014 at 7:07 PM, Jeremy Mauro
<
>
wrote:
>
Hi everyone,
>
>
>
>
In the documentation it is not clearly in which version of chef the
>
attribute ‘convert_boolean_return’ and ‘interpreter’ has been introduced,
>
because we are using chef-11-10-4 and it doesn’t seem to be implemented in
>
this version.
>
>
Do you think it could be possible to have a better highlight of the version
>
where the attributes were introduced, because it is not clear see where to
>
search such information except from reading directly the chef-client code.
>
>
>
>
Thx
>
>
>
>
>
>
>
>
>
>
>
>
>
>
From: Adam Edwards
>
[mailto:
>
Sent: mercredi 20 août 2014 18:09
>
To:
>
>
Subject: [chef] RE: Re: Re: NOT_IF and ONLY_IF validation problem.
>
>
>
>
Carlos, $lastexitcode does not give you the exit status of the last
>
powershell cmdlet, it gives you the last exit status of a Windows process
>
that you executed. Since get-website is a cmdlet, lastexitcode tells you
>
nothing about its success or failure. For cmdlet status, use $?, which is
>
$true if the last cmdlet succeeded, $false otherwise.
>
>
>
>
Powershell_script actually has a feature to make your scenario easy – just
>
provide a boolean expression to your guard, something like (get-website |
>
where-object { $_.name -eq 'My_Web_App' }).length > 0, which will return
>
$true if there’s a web site satisfying the query (assuming get-website
>
returns a collection with a length property) and $false otherwise.
>
>
>
>
You can read more about this capability in this documentation from
>
http://docs.getchef.com/resource_powershell_script.html -- see the excerpt
>
below:
>
>
>
>
>
>
convert_boolean_return
>
>
Use to return 0 if the last line of a command is evaluated to be true or to
>
return 1 if the last line is evaluated to be false. Default value: false.
>
>
>
>
When the guard_intrepreter common attribute is set to :powershell_script, a
>
string command will be evaluated as if this value were set to true. This is
>
because the behavior of this attribute is similar to the value of the "$?"
>
expression common in UNIX interpreters. For example, this:
>
>
>
>
powershell_script 'make_safe_backup' do
>
>
guard_interpreter :powershell_script
>
>
code 'cp ~/data/nodes.json ~/data/nodes.bak'
>
>
not_if 'test-path ~/data/nodes.bak'
>
>
end
>
>
is similar to:
>
>
>
>
bash 'make_safe_backup' do
>
>
code 'cp ~/data/nodes.json ~/data/nodes.bak'
>
>
not_if 'test -e ~/data/nodes.bak'
>
>
end
>
>
>
>
From: Seth Vargo
>
[mailto:
>
Sent: Wednesday, August 20, 2014 7:55 AM
>
To:
>
>
Subject: [chef] Re: Re: NOT_IF and ONLY_IF validation problem.
>
>
>
>
Hi Carlos,
>
>
>
>
You also posted this question on StackOverflow:
>
http://stackoverflow.com/questions/25406353/chef-not-if-and-only-if-validation-issue-in-windows-recipes.
>
>
>
>
I understand that you are trying to get the fastest answer possible, but
>
posting the same question in multiple channels, you may discourage the
>
chances of getting an answer. It gives a wry impression. Here's what I would
>
recommend:
>
>
>
>
- If you have a question and you need an answer NOW, IRC is the best bet.
>
You will get real-time communication with members of Chef and the Chef
>
community.
>
>
- If you have a question that is about process, best practice, or opinion,
>
this mailing list is probably your best bet. If you need to show code on the
>
mailing list, using a service like PasteBin or GitHub Gist can make the
>
email more readable.
>
>
- If you have a specific code example (i.e. why is this failing),
>
StackOverflow/ServerFault are usually the best.
>
>
>
>
I realize there are definitely areas for overlap, so please use your best
>
judgement.
>
>
>
>
Thanks,
>
>
Seth
>
>
>
>
On Aug 20, 2014, at 10:40 AM, Julian C. Dunn
>
<
>
>
wrote:
>
>
>
>
On Wed, Aug 20, 2014 at 8:16 AM, Carlos Camacho
>
<
>
>
wrote:
>
>
Hello!
>
>
Im runing this simple recipe block to create a web app in IIS
>
>
powershell_script "create_site_my_site" do
>
code "New-webapppool -name 'My_Web_App'; New-Website -Name
>
'My_Web_App' -applicationpool 'My_Web_App' -Port '80' -IPAddress *
>
-PhysicalPath 'c:\webs\My_Web_App' "
>
action :run
>
not_if "get-website | where-object { $_.name -eq 'My_Web_App' }"
>
end
>
>
>
The problem here its that the NOT_IF part its allways True
>
>
>
PS C:\Users\carlos>
>
PS C:\Users\carlos> get-website | where-object { $_.name -eq 'asdfasdfasdf'
>
}
>
PS C:\Users\carlos> echo $lastexitcode
>
1
>
PS C:\Users\carlos> get-website | where-object { $_.name -eq 'My_Web_App' }
>
>
Name ID State Physical Path
>
Bindings
>
---- -- ----- -------------
>
--------
>
My_Web_App 6 Stopped c:\webs\My_Web_App http *:80:
>
>
https *:443:
>
>
PS C:\Users\carlos.camacho> echo $lastexitcode
>
1
>
>
Now, my question is about how to return True or False in the NOT_IF
>
depending on my code return value ??
>
>
>
Use the convert_boolean_return attribute in the powershell_script
>
resource to do the right thing. See the documentation for information
>
about what that does & why.
>
>
http://docs.getchef.com/resource_powershell_script.html
>
>
I imagine that this will become the default when :guard_interpreter
>
becomes :powershell by default for powershell_script.
>
>
- Julian
>
>
--
>
[ Julian C. Dunn
>
<
>
>
* Sorry, I'm ]
>
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
>
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
>
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]
>
>
Archive powered by MHonArc 2.6.16.