Writing to shell from a ps1 script worked for me. Here is the recipe
powershell_script "TestConsoleOutput1" do
code <<-EOH
$command = "powershell C:\\script.ps1"
Invoke-_expression_ -Command $command
EOH
End
The ps1 script file has ‘Write-Host
"-------------------------------> Writing from the script file" ‘
Following is the output of chef-run:
* powershell_script[TestConsoleOutput1] action run[2014-05-01T20:09:35-04:00] INFO: Processing powershell_script[TestConsoleOutput1] action run (testcookbook::testrecipe
line 100)
-------------------------------> Writing from the script file
-Kapil
From: Kimly Heler [mailto:
Sent: Thursday, May 1, 2014 7:59 PM
To:
Subject: [chef] Re: RE: Re: RE: Re: RE: Need help on printing output console from a command on the chef run
Wow awesome!
I'm wondering why I have to put the ps1 content in the code, instead of calling it from a separate ps1 file, in order to see the output.
I never tried to put the content directly into it, as my ps1 file is almost 1000 line long. I know this is not a very good approach, but for now my team wanted to write a chef wrapper to call execute it, and break it down into pieces later
if possible.
Is there a better way to archive this or I really have to put everything in it? :(
But it's wonderful that I know printing the output is possible.
On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <
" target="_blank">
> wrote:
I just did a quick test. Here is my recipe:
powershell_script "TestConsoleOutput" do
code <<-EOH
Write-host "---------------> Writing to the console"
EOH
End
And here is the chef-client output. It does print the result of Write-Host cmdlet to the shell:
* powershell_script[TestConsoleOutput] action run[2014-05-01T19:40:33-04:00] INFO: Processing powershell_script[TestConsoleOutput] action run
(testcookbook::testrecipe line 92)
---------------> Writing to the console
[2014-05-01T19:40:34-04:00] INFO: powershell_script[TestConsoleOutput] ran successfully
-Kapil
From: Kimly Heler [mailto:
" target="_blank">
]
Sent: Thursday, May 1, 2014 7:31 PM
To:
" target="_blank">
Subject: [chef] Re: RE: Re: RE: Need help on printing output console from a command on the chef run
Hi Kapil, so I thought about it just now, using locate_sysnative_cmd in powershell_script resource, which I never tried before.
But turned out powershell_script acts similar to execute, which didn't print out anything when it ran successfully:
[2014-05-01T23:27:02+00:00] INFO: powershell_script[Running windows finishing] ran successfully
[2014-05-01T23:27:02+00:00] INFO: Chef Run complete in 0.921875 seconds
On Thu, May 1, 2014 at 3:41 PM, Kapil Shardha <
" target="_blank">
> wrote:
I was wondering if you have tried using powershell_script resources and “copied” your ps1 file content in it. Something like this:
Powershell_resource “InstallSomething” do
code <<-EOH
<Content of your ps1 file>
EOH
end
I had problem with powershell_script in my production provision as it confused between 32bit and 64bit powershell or something like that, causing it to unable to call the ps1 script, wasn't exactly sure the cause.
I have to use locate_sysnative_cmd("powershell.exe") and it did the trick.
The funny thing is my vagrant worked just fine with or without the trick.
Have you tried using powershell_script resource?
-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To:
" target="_blank">
Subject: [chef] Need help on printing output console from a command on the chef run
Hi,
I have a chef block code like this:
execute "Test to capture log" do
command "powershell.exe -executionpolicy Bypass -command \"&
C:\\vagrant\\test.ps1\""
end
The test.ps1 will print out to the console something, while also logging it to
a log file.
When I do vagrant provision, how can I display what test.ps1 prints out at the
ON-GOING chef run?
I see that the 'execute' doesn't print out anything if it runs successfully,
otherwise it will shell out the error AT THE END OF THE RUN.
I also tried Chef::Mixin::ShellOut:
ruby_block "Running windows finishing script" do
block do
require 'chef/mixin/shell_out'
extend Chef::Mixin::ShellOut
Chef::Log.info "This will take a while to complete. Sit back and have some
beer."
results = shell_out "powershell.exe -executionpolicy Bypass -command \"&
C:\\vagrant\\test.ps1\""
Chef::Log.info "Output: #{ results.stdout }"
end
end
And again, it still didn't print out anything until the end of the run.
My actual ps1 will install several middleware applications, takes about 10 mins
to complete, so I try to print out the output console while it's running to
show its progress.
Any help will be very appreciated.
~Kimly
This email and any accompanying documents may contain privileged or otherwise confidential information of, and/or is the property of Education Management Solutions, Inc. If you are not the intended recipient, please immediately advise the sender by reply email
& delete the message & any attachments without using, copying or disclosing the contents. Thank you.
This email and any accompanying documents may contain privileged or otherwise confidential information of, and/or is the property of Education Management Solutions, Inc. If you are not the intended recipient, please immediately advise the sender by reply email
& delete the message & any attachments without using, copying or disclosing the contents. Thank you.
This email and any accompanying documents may contain privileged or otherwise confidential information of, and/or is the property of Education Management Solutions, Inc. If you are not the intended recipient, please immediately advise the sender by reply email
& delete the message & any attachments without using, copying or disclosing the contents. Thank you.
This email and any accompanying documents may contain privileged or otherwise confidential information of, and/or is the property of Education Management Solutions, Inc. If you are not the intended recipient, please immediately advise the sender by reply email
& delete the message & any attachments without using, copying or disclosing the contents. Thank you.
|