Hello,
 
Thanks for getting back to me.
 
I think I forgot to mention, I am using this:
 
http://forge.puppetlabs.com/joshcooper/powershell
 
Does this "change" how the onlyif parameter interprets what it is provided?
 
Thanks

Gary

On Tuesday, April 16, 2013 3:54:19 PM UTC+1, jcbollinger wrote:

>
>
> On Monday, April 15, 2013 9:14:21 AM UTC-5, Gary Park wrote:
>>
>> Hello,
>>
>> I am in the process of "trying out" Puppet, and so far, it is going 
>> really well, and I can see a clear line of how we can use it internally.
>>
>> I do have one question though with regard to the using the onlyif 
>> parameter of the exec command (as per here 
>> http://docs.puppetlabs.com/references/latest/type.html#exec).
>>
>> Ideally, what I would like to do is to only run a PowerShell exec 
>> command, if a web page doesn't currently exist on the server (i.e. the 
>> PowerShell script is responsible for deploying the Web Pages (into 
>> SharePoint in this case) and I only want to run this step, if these pages 
>> don't already exist.  To that end, I have done something like this:
>>
>> onlyif => '$webRequest = [System.Net.WebRequest]::Create("
>> http://some-url.test.aspx";); $webRequest.UseDefaultCredentials = $true; 
>> try { if([int]$webRequest.GetResponse().StatusCode -eq "200") { exit 0; } 
>> else { exit 1; } } catch [System.Net.WebException] { exit 1; }'
>>
>> Which, at the command line, has the correct result.  However, when I try 
>> to run this, I get an error saying that $webRequest is not recognised.
>>
>  
>
> Puppet invokes the specified command directly, not via the [standard | 
> Power] shell, so whether that works at the (some) command line is 
> irrelevant.
>
>  
>
>>
>> Which leads me to think that using variables within the onlyif is not 
>> supported.  Is that correct?  If so, what is the best approach for doing 
>> this, or am I going up the wrong path?
>>
>>
>
> No, that's not correct.  I suppose you expect '$webRequest' to be 
> meaningful to (and the whole command sequence to be executed by) 
> PowerShell, but you haven't told Puppet to run it via PowerShell.  Instead, 
> you've told Puppet to execute a command named literally '$webRequest'.  
> Refer to the docs on the Exec type's "windows" provider for information and 
> examples of how to make this sort of thing work: 
> docs.puppetlabs.com/references/3.1.latest/type.html#exec .  What they say 
> about the 'command' parameter applies equally to 'onlyif'.
>
>
> John
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to