PowerShell - chef logs and ending a run

Hi,

I use the package resource to install a application which ends and returns the success code.

As its a large complex app I’d also like to do a sanity check in the logs to see that it actually was completed and end the run if fails. I.e. I don’t think I can just reply on the package return code.

powershell_script ‘Confirm Installation Successful’ do
code <<-EOH
$file = Get-Content “E:\Apps\Appx\technical_installation.log”
$containsWord = file | %{_ -match “Applicationx Version 1.1.1.1 – Installation operation completed successfully”}
if ($containsWord -contains $true) {
Chef::Log.info(‘Upgrade Sucessful’)
} else {
Chef::Log.fatal(‘Upgrade failed’)
}
EOH
end

I’m mixing Powershell and native Chef with the “Chef::Log.info(‘Upgrade Sucessful’)” & “Chef::Log.fatal(‘Upgrade failed’)” so doesn’t work.

How do others do this type of checking in the Chef windows world?

Many thanks

For validation I would use inspec , which would run after the node was converged by chef. InSpec could be invoked manually or automatically right after convergence.
If this check would be necessary because additional steps should be done by chef based on the check result, then I would create an LWRP

1 Like

Hi,

We’re using Chef to manage a vendor app that needs licensing locked to each server so I cannot use dynamically created app servers and inspec unfortunately.

any suggestions for the old way I was attempting?

many thanks

David

Here is a good guide that could help