- From: "David A. Williams" <
>
- To: "
" <
>, "
" <
>
- Subject: [chef] Re: RE: Is a Chef Resource that returns a boolean value?
- Date: Fri, 7 Feb 2014 06:33:04 -0600
- Accept-language: en-US
- Acceptlanguage: en-US
Adam,
Yes, that would be helpful! Below is an example of one I'm using to see if a
user already has the logon on as a service permission which is similar.
powershell_script "Add Log On As A Service Right to #{params[:user]}" do
code <<-EOH
#{Dir.tmpdir()}/LogOnAsAService.ps1 -user #{params[:user]}
-addPermission
EOH
only_if{`powershell.exe -ExecutionPolicy RemoteSigned
#{Dir.tmpdir()}/LogOnAsAService.ps1 -user
#{params[:user]}`.downcase.include?('has permission = false')}
end
I'm also messing around with calling helper methods in a module to abstract
the code a little bit. This is proving tricky. I've learned that only class
module methods work within resources but class module methods don't have
access to Chef resources. This part of ruby is new to me but good learning
experience.
Thank you,
David Williams
From: Adam Edwards
<
<mailto:
>>
Reply-To:
"
<mailto:
>"
<
<mailto:
>>
Date: Friday, February 7, 2014 2:10 AM
To:
"
<mailto:
>"
<
<mailto:
>>,
"
<mailto:
>"
<
<mailto:
>>
Subject: [chef] RE: Is a Chef Resource that returns a boolean value?
Correction: actually, in the example below, the workaround must be inverted,
so a "!” needs to be added:
powershell –command "exit [int32](!(get-executionpolicy) -eq
'remotesigned'))"
-Adam
From: Adam Edwards
[mailto:
<mailto:
>]
Sent: Thursday, February 6, 2014 10:57 PM
To:
'
<mailto:
>'
Subject: RE: [chef] Is a Chef Resource that returns a boolean value?
David, I have a branch in progress that adds this feature to
powershell_script (if I understand you correctly). See the doc at
https://github.com/opscode/chef-rfc/blob/adamed/resource-guard/rfc0001-resource-guard.md
-- it has a link to a branch.
Is this the behavior you'd like to see?
# What if guards evaluated powershell script code that powershell
# evaluates as a boolean type as the actual boolean value of the guard
# itself? You can avoid extra script code to translate the boolean into
# a process exit code that results in the right true / false behavior
# for the guard
powershell_script "set execution policy" do
code "set-executionpolicy remotesigned"
not_if "(get-executionpolicy) -eq 'remotesigned'" # Like I barely left
Ruby -- wow!
end
The current workaround for the example above is to use an expression like
powershell –command "exit [int32](get-executionpolicy) -eq 'remotesigned')"
in the not_if above. It basically forces the script to convert a Boolean data
type to an integer that is then returned as the process exit code, which is
interpreted by Chef as a Boolean value.
-Adam
-----Original Message-----
From: David A. Williams
[mailto:
Sent: Thursday, February 6, 2014 7:36 PM
To: Chef users
Subject: [chef] Is a Chef Resource that returns a boolean value?
I work with Chef on Windows node and find myself writing a lot of Chef guards
for the powershell_script resource. I was wondering if there was a Chef
resource that returned a boolean value that I could use here.
Thank you,
David Williams
________________________________
CONFIDENTIALITY NOTICE: This electronic mail may contain information that is
privileged, confidential, and/or otherwise protected from disclosure to
anyone other than its intended recipient(s). Any dissemination or use of this
electronic mail or its contents by persons other than the intended
recipient(s) is strictly prohibited. If you have received this communication
in error, please notify the sender immediately by reply e-mail so that we may
correct our internal records. Please then delete the original message. Thank
you.
________________________________
CONFIDENTIALITY NOTICE: This electronic mail may contain information that is
privileged, confidential, and/or otherwise protected from disclosure to
anyone other than its intended recipient(s). Any dissemination or use of this
electronic mail or its contents by persons other than the intended
recipient(s) is strictly prohibited. If you have received this communication
in error, please notify the sender immediately by reply e-mail so that we may
correct our internal records. Please then delete the original message. Thank
you.
Archive powered by MHonArc 2.6.16.