Why does Chef-Client have different outputs in PowerShell? - powershell

When I run Chef-Client in PowerShell and allow the process to output to the screen using the following command:
& Chef-Client -z -r "chef-cookbook"
I get this output:
[2014-11-10T07:20:40-08:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 11.16.4
resolving cookbooks for run list: ["chef-cookbook"]
Synchronizing Cookbooks:
- chef-cookbook
- powershell-automation
Compiling Cookbooks...
Converging 2 resources
Recipe: powershell-automation::Port_Configuration
* powershell_script[Port_Configuration] action run (skipped due to not_if)
Recipe: powershell-automation::IIS_InstallAutomation
* powershell_script[IIS_InstallAutomation] action run (skipped due to not_if)
Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 43.69728 seconds
When I run the same command, but capture it to a variable, using the following command:
$chefOutput = & Chef-Client -z -r "chef-cookbook"
The $chefOutput variable contains:
[2014-11-10T07:23:01-08:00] WARN: No config file found or specified on command line, using command line options.
[2014-11-10T07:23:01-08:00] INFO: Auto-discovered chef repository at C:/Temp
[2014-11-10T07:23:01-08:00] INFO: Starting chef-zero on host localhost, port 8889 with repository at repository at C:/Temp
One version per cookbook
[2014-11-10T07:23:06-08:00] INFO: *** Chef 11.16.4 ***
[2014-11-10T07:23:06-08:00] INFO: Chef-client pid: 3364
[2014-11-10T07:23:37-08:00] INFO: Setting the run_list to [recipe[chef-cookbook]] from CLI options
[2014-11-10T07:23:37-08:00] INFO: Run List is [recipe[chef-cookbook]]
[2014-11-10T07:23:37-08:00] INFO: Run List expands to [chef-cookbook]
[2014-11-10T07:23:37-08:00] INFO: Starting Chef Run for XXXXX.XXX.XXX.XXX.com
[2014-11-10T07:23:37-08:00] INFO: Running start handlers
[2014-11-10T07:23:37-08:00] INFO: Start handlers complete.
[2014-11-10T07:23:37-08:00] INFO: HTTP Request Returned 404 Not Found : Object not found: /reports/nodes/XXXXX.XX.XX.XX.com/runs
[2014-11-10T07:23:37-08:00] INFO: Loading cookbooks [chef-cookbook#2015.1.0, powershell-automation#2015.1.0]
[2014-11-10T07:23:37-08:00] INFO: Processing powershell_script[Port_Configuration] action run (powershell-automation::Port_Configuration line 22)
[2014-11-10T07:23:37-08:00] INFO: Processing bash[Guard resource] action run (dynamically defined)
[2014-11-10T07:23:38-08:00] INFO: bash[Guard resource] ran successfully
[2014-11-10T07:23:38-08:00] INFO: Processing powershell_script[IIS_InstallAutomation] action run (powershell-automation::IIS_InstallAutomation line 16)
[2014-11-10T07:23:43-08:00] INFO: Chef Run complete in 6.346486 seconds
[2014-11-10T07:23:43-08:00] INFO: Running report handlers
[2014-11-10T07:23:43-08:00] INFO: Report handlers complete
Why does this discrepancy between outputs happen?
Note: I am seeing that the output in the variable also contains the time stamps and INFO tags for each line. Based on this, I believe this is something to do with how Chef outputs vs something to do with PowerShell.

It checks if stdout is a TTY.

Related

Sonar scanner github action fails intermittently with “Fail to parse entry in bootstrap index”. Passes on re-run of the job

Which versions am I using
I'm using Sonarqube CE 8.9 hosted in Google cloud VM accessible via an internal domain URL.
Github action runs sonar scanner as part of PR builds on a web app project: SonarSource/sonarqube-scan-action#v1.1.0
what problem am I facing?
Sonar scanner github action intermittently fails with Fail to parse entry in bootstrap index: <!DOCTYPE html>.
If the job is run again, it successfully completes. So I'm not sure what is going wrong.
This is the log from sonar scanner run with verbose=true
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
06:39:11.701 INFO: SonarScanner 4.7.0.2747
06:39:11.702 INFO: Java 11.0.17 Alpine (64-bit)
06:39:11.703 INFO: Linux 5.15.0-1022-azure amd64
06:39:11.837 DEBUG: keyStore is :
06:39:11.838 DEBUG: keyStore type is : pkcs12
06:39:11.838 DEBUG: keyStore provider is :
06:39:11.839 DEBUG: init keystore
06:39:11.839 DEBUG: init keymanager of type SunX509
06:39:11.981 DEBUG: Create: /opt/sonar-scanner/.sonar/cache
06:39:11.982 INFO: User cache: /opt/sonar-scanner/.sonar/cache
06:39:11.982 DEBUG: Create: /opt/sonar-scanner/.sonar/cache/_tmp
06:39:11.984 DEBUG: Extract sonar-scanner-api-batch in temp...
06:39:11.987 DEBUG: Get bootstrap index...
06:39:11.987 DEBUG: Download: ***/batch/index
06:39:12.678 DEBUG: Get bootstrap completed
06:39:12.681 INFO: ------------------------------------------------------------------------
06:39:12.681 INFO: EXECUTION FAILURE
06:39:12.681 INFO: ------------------------------------------------------------------------
06:39:12.681 INFO: Total time: 1.015s
06:39:12.697 INFO: Final Memory: 4M/17M
06:39:12.698 INFO: ------------------------------------------------------------------------
06:39:12.699 ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to parse entry in bootstrap index: <!DOCTYPE html>
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.parse(BootstrapIndexDownloader.java:59)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:44)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 7 more
06:39:12.706 ERROR:
06:39:12.706 ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
what have I tried to debug this issue?
I checked whether there is any issue with the sonar URL but it is fine because the scanner works fine otherwise. Apart from this I'm not sure what else I can check.
Also is there a difference between running the sonar scanner with -X and running it with -Dsonar.verbose=true ?

How to solve "ERROR: Import of Jasper report server export zip failed!"

I am getting the following error when trying to run js-import script as root user.
INFO: Jasper report server install successful!
PORTAL_HOME =
cp: cannot stat ‘/jasper/install/distributions/jasperReports/lib/*’: No such file or directory
Using CATALINA_BASE: /opt/jasper/tomcat/apache-tomcat-9.0.56
Using CATALINA_HOME: /opt/jasper/tomcat/apache-tomcat-9.0.56
Using CATALINA_TMPDIR: /opt/jasper/tomcat/apache-tomcat-9.0.56/temp
Using JRE_HOME: /usr/java/jdk1.8.0_312
Using CLASSPATH: /opt/jasper/tomcat/apache-tomcat-9.0.56/bin/bootstrap.jar:/opt/jasper/tomcat/apache-tomcat-9.0.56/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Using CATALINA_PID: /opt/jasper/tomcat/apache-tomcat-9.0.56/catalina_pid.txt
Existing PID file found during start.
Removing/clearing stale PID file.
Tomcat started.
Waiting on Tomcat to start - Retry 1/5 in 60s
INFO: Tomcat started Successfully!
Running the JS import script [/jasper/install/scripts/runJSTestInstall.sh.tmp].
ERROR: Import of Jasper report server export zip failed!
ERROR: Main install failed while executing child script [installJasperReports]!
INFO: Check the [installJasperReports.log] file for more details.
INFO: Fix the issue and then run [uninstallJasperReports.sh /jasper/install] followed by [installAll.sh /jasper/install installJasperReports] to resume.
I get the below log in js-import file relevant to the above error.
VALIDATION COMPLETED
Total time: 4 seconds
Executing CE version
First resource path: /opt/jasper/jasperReports/jasperreports-server-cp-8.0.0-bin/buildomatic/conf_source/ieCe
Loading configuration resources
Initialization complete
Processing started
Tenant not found with Tenant ID "organizations"
Please give a solution for this!

Execution Chef Cookbook using chef-solo

I am trying to execute chef solo on my windows vm locally using Powershell. (I am trying to execute cookbook during provisioning customise Windows VM on cloud)
All cookbook recipe dependencies are available within the cookbook.
Create solo.rb for recipe execution & web.json to run recipe.
"type": "powershell",
"inline": "chef-client --chef-license=accept -z -o cookbooks\\cookbook_workstation"
Error:
WARN: Failed to read the private key C:\chef\client.pem: #<Errno::ENOENT: No such file or directory # rb_sysopen - C:\chef\client.pem>
WARN: Error while reporting run start to Data Collector. URL: https://localhost:443/data-collector Exception: No HTTP Code -- I cannot read C:\chef\client.pem, which you told me to use to sign requests!
FATAL: NoMethodError: undefined method logger' for nil:NilClass <internal:warning>:43:in warn': warning: Chef::Compliance::Runner#logger at C:/opscode/chef/embedded/lib/ruby/2.7.0/forwardable.rb:154 forwarding to private method NilClass#logger (StructuredWarnings::BuiltInWarning)
Using chef-solo so I don't need chef server - how can I overcome client.pem WARN and logger issue. Pointers would be very helpful

running a command in Raspberry Pi boot

I tried 3 different method no succeded for running the code
cd amazon-kinesis-video-streams-producer-sdk-cpp/build
./kvs_gstreamer_sample PiStream
we get following errors
[09-12-2020 15:06:12:496.703 GMT] Using region: us-west-2 [ERROR]
[09-12-2020 15:06:12:514.317 GMT] No valid credential method was found
[ERROR] [09-12-2020 15:06:12:515.086 GMT] Failed to initialize kinesis
video with an exception: No valid credential method was found
I am trying to run a cpp code which has some AWS dependencies which says we could not define the paths in the boot even though we added in 3 different method
adding commands into local.rc
adding crontab -e
and adding bash.rc
after booting ia can run the comman from terminal successfully.
How can we define the some parameters in the booth of raspberry pi

chef recipe doesn't find ohai plugin defined resource

I want to add additional resource 'version of installed openssh' to Ohai to use it in my openssh maintaining recipe.
On RHEL 5.11 Chef 12.4.1 Ohai 8.5.0 test workstation I have created and tested Ohai plugin
$ cat cookbooks/test/files/default/plugins/openssh.rb
Ohai.plugin(:Openssh) do
provides "openssh"
Ohai::Log.debug('plugin start')
def create_objects
openssh Mash.new
end
collect_data do
create_objects
openssh[:version] = 'ssh -V 2>&1 |head -1| cut -d, -f1| cut -d_ -f2 '
end
end
Local test of ohai plugin in irb is working fine.
Now I'm trying to check resource visibility in Chef recipe
$ cat test/recipes/default.rb
file "#{ENV['HOME']}/x.txt" do
content 'HELLO WORLD'
end
output="#{Chef::JSONCompat.to_json_pretty(node.to_hash)}"
file '/tmp/node.json' do
content output
end
Chef::Log.info("============ test cookbook ** #{openssh['version']} **")
\#Chef::Log.info("============ test cookbook ** #{node['kernel']} **")
by running local chef-client
$ chef-client -z -m test/recipes/default.rb
To make additional plugin visible line is added to config files
$grep Ohai ~/.chef/*.rb
~/.chef/client.rb:Ohai::Config[:plugin_path] << '~/chef/cookbooks/test/files/default/plugins/'
~/.chef/knife.rb:Ohai::Config[:plugin_path] << '~/chef/cookbooks/test/files/default/plugins/'
(I understand that this is too explicit )
Although running with printing node['kernel'] is working fine , openssh version is not running with debug log that shows:
[2016-01-27T11:48:21-08:00] DEBUG: Cookbooks detail: []
[2016-01-27T11:48:21-08:00] DEBUG: Cookbooks to compile: []
[2016-01-27T11:48:21-08:00] DEBUG: **Loading Recipe File XXX/cookbooks/test/recipes/default.rb**
[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic file resource enabled on node include: [Chef::Resource::File]
[2016-01-27T11:48:21-08:00] DEBUG: Resource for file is Chef::Resource::File
[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic file resource enabled on node include: [Chef::Resource::File]
[2016-01-27T11:48:21-08:00] DEBUG: Resource for file is Chef::Resource::File
[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic openssh resource enabled on node include: []
[2016-01-27T11:48:21-08:00] DEBUG: **Dynamic resource resolver FAILED to resolve a resource for openssh**
[2016-01-27T11:48:21-08:00] DEBUG: Re-raising exception: NameError - No resource, method, or local variable named `openssh' for `Chef::Recipe "XXX/cookbooks/test/recipes/default.rb"'
Questions:
How properly chef out additional plugin to recipe for local and remote execution? How to check that it is cheffed out and ready?
How properly notify chef-client to execute ohai additional plugin for local single recipe run and for remote run as well?
Any explanations and suggestions are welcomed.
Alex
A few issues: first check out https://github.com/coderanger/ohai-example to see how to package an ohai plugin in a cookbook for distribution. Second, node attributes from custom plugins still need to be accessed via the node object: node['openssh']['version']. Third, remember how execution ordering works in Chef (https://coderanger.net/two-pass/) and that the custom attributes won't be available until after the plugin is loaded and run.
Checkout mainstream before google!
This project describes how to deploy you plugin in 2017 year!
https://github.com/chef-cookbooks/ohai