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

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha Kapil.Shardha@SimulationIQ.com wrote:

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.

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

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha <Kapil.Shardha@SimulationIQ.commailto:Kapil.Shardha@SimulationIQ.com> wrote:
Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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.

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 <
Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a
command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha Kapil.Shardha@SimulationIQ.com
wrote:

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.

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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.com
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 <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Cc: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha <Kapil.Shardha@SimulationIQ.commailto:Kapil.Shardha@SimulationIQ.com> wrote:
Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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.

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? :frowning:

But it's wonderful that I know printing the output is possible.

Thanks Kapil.

On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> 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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.com
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 <
Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a
command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha Kapil.Shardha@SimulationIQ.com
wrote:

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.

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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:59 PM
To: chef@lists.opscode.com
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? :frowning:

But it’s wonderful that I know printing the output is possible.

Thanks Kapil.

On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> 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:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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 <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Cc: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha <Kapil.Shardha@SimulationIQ.commailto:Kapil.Shardha@SimulationIQ.com> wrote:
Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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.

Hi Kapil,

Somehow none of them reported the output for me, even though chef ran
successfully.

I used your two examples, and I got the same result on both cases:

[2014-05-02T18:52:46+00:00] INFO: powershell_script[TestConsoleOutput1] ran
successfully
[2014-05-02T18:52:46+00:00] INFO: Chef Run complete in 0.859375 seconds

I'm using vagrant 1.3.5, chef 11.10.2.

On Thu, May 1, 2014 at 5:12 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> wrote:

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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:59 PM
To: chef@lists.opscode.com
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? :frowning:

But it's wonderful that I know printing the output is possible.

Thanks Kapil.

On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> 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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.com
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 <
Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a
command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha Kapil.Shardha@SimulationIQ.com
wrote:

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.

I did my test on a VM running Chef client 11.8.2 with windows Server 2012.

I tried on a different VM running Chef client 11.12.0 and Windows 8 and ran into the issue you are facing. Seems like something changed during these versions that changed the behavior of powershell_resource. You may want to report it as a bug unless someone from Opscode team has some explanation around it.

Thanks

-Kapil

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Friday, May 2, 2014 2:57 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: RE: Re: RE: Need help on printing output console from a command on the chef run

Hi Kapil,

Somehow none of them reported the output for me, even though chef ran successfully.

I used your two examples, and I got the same result on both cases:

[2014-05-02T18:52:46+00:00] INFO: powershell_script[TestConsoleOutput1] ran successfully
[2014-05-02T18:52:46+00:00] INFO: Chef Run complete in 0.859375 seconds

I’m using vagrant 1.3.5, chef 11.10.2.

On Thu, May 1, 2014 at 5:12 PM, Kapil Shardha <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> wrote:
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:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:59 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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? :frowning:

But it’s wonderful that I know printing the output is possible.

Thanks Kapil.

On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> 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:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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 <Kapil.Shardha@simulationiq.commailto:Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.commailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Cc: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha <Kapil.Shardha@SimulationIQ.commailto:Kapil.Shardha@SimulationIQ.com> wrote:
Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.commailto:chef@lists.opscode.com
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.


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.

Thank you Kapil for your help. Much appreciated. I will raise a bug for it.

On Fri, May 2, 2014 at 12:09 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> wrote:

I did my test on a VM running Chef client 11.8.2 with windows Server
2012.

I tried on a different VM running Chef client 11.12.0 and Windows 8 and
ran into the issue you are facing. Seems like something changed during
these versions that changed the behavior of powershell_resource. You may
want to report it as a bug unless someone from Opscode team has some
explanation around it.

Thanks

-Kapil

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Friday, May 2, 2014 2:57 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: RE: Re: RE: Need help on printing
output console from a command on the chef run

Hi Kapil,

Somehow none of them reported the output for me, even though chef ran
successfully.

I used your two examples, and I got the same result on both cases:

[2014-05-02T18:52:46+00:00] INFO: powershell_script[TestConsoleOutput1]
ran successfully

[2014-05-02T18:52:46+00:00] INFO: Chef Run complete in 0.859375 seconds

I'm using vagrant 1.3.5, chef 11.10.2.

On Thu, May 1, 2014 at 5:12 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> wrote:

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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:59 PM
To: chef@lists.opscode.com
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? :frowning:

But it's wonderful that I know printing the output is possible.

Thanks Kapil.

On Thu, May 1, 2014 at 4:42 PM, Kapil Shardha <
Kapil.Shardha@simulationiq.com> 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:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 7:31 PM
To: chef@lists.opscode.com
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 <
Kapil.Shardha@simulationiq.com> 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

From: Kimly Heler [mailto:kimlyheler@gmail.com]
Sent: Thursday, May 1, 2014 6:37 PM
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: Need help on printing output console from a
command on the chef run

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.

On May 1, 2014, at 3:02 PM, Kapil Shardha Kapil.Shardha@SimulationIQ.com
wrote:

Have you tried using powershell_script resource?

Kapil

-------- Original message --------
From: Kimly
Date:05/01/2014 5:55 PM (GMT-05:00)
To: chef@lists.opscode.com
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.


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.