Is there any way to run PowerShell scripts in Serverspec? - ruby

There are lots of build-in resources in Serverspec, but I want to extend it to my own needs. In InSpec it support script resource which will run the PowerShell script and get the result it seems.
But InSpec is too slow. Is there any equivalent to script resource in Serverspec exists? It is running PowerShell script in the backend for each resource. How to write my own PowerShell script and call it via Serverspec?

Related

Creating User to run specific powershell script

I'm trying to create a user in windows which will only be able to run specific scripts ie, test.ps1, and running all other types of scripts should be blocked. If there is any way to do that.
Path of test.ps1 = C:/Program files/test.ps1

How to run .rb script using jmeter gui

I am trying to perform load test using jmeter. I have my script to extract and generate .json output file which is using ruby. Now i want to use this output.json ( which changes with every thread event) in jmeter and run it with 100 threads. How do I call .rb using jmeter gui?
You can use OS Process Sampler to invoke whatever external command or program from JMeter test script.
Example configuration:
Change:
c:\apps\ruby\bin\ruby.exe to the actual path to your ruby executable
c:\temp\script.rb to the actual path of your .rb script
More information: How to Run External Commands and Programs Locally and Remotely from JMeter
You can execute ruby in JMeter using jruby script engine
Dowonload jruby-engine.jar
Copy to JMeter lib directory with ruby relevant jars (as jruby-core)
In JSR223 choose language as jruby
Write your ruby script and run test
Notice that JRuby find predefined variable using $ prefix:
$log.info("Hello from JRuby");

Windows GitLab CI Runner using Bash

I'm trying to use bash as the shell on Windows for a GitLab CI Runner.
concurrent = 1
check_interval = 0
[[runners]]
name = "DESKTOP-RQTQ13S"
url = "https://example.org/ci"
token = "fooooooooooooooooooobaaaaaaaar"
executor = "shell"
shell = "bash"
[runners.cache]
Unfortunately I can not find an option to specify the actual shell program that the CI Runner should use. By default, it just tries to run bash which it can not find. I don't know why, because when I open up a Windows command line and enter bash it works.
Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
ERROR: Build failed (system failure): Failed to start process: exec: "bash": executable file not found in %PATH%
I tried adding a file bash.cmd to my user directory containing
#"C:\Program Files\Git\usr\bin\bash.exe" -l
That gives me this strange error:
Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
Running on DESKTOP-RQTQ13S...
/usr/bin/bash: line 43: /c/Users/niklas/C:/Users/niklas/builds/aeb38de4/0/niklas/ci-test.tmp/GIT_SSL_CAINFO: No such file or directory
ERROR: Build failed: exit status 1
Is there a way to properly configure this?
There are two issues going on here, and both can probably be solved.
gitlab-runner cannot find bash
gitlab-runner doesn't combine unix-style and Windows-style paths very well.
You have essentially succeeded in solving the first one by creating the bash.cmd file. But if you're curious about why it didn't work without it, my guess is that bash runs in your command prompt because the directory that contains it (e.g. in your case "C:\Program Files\Git\usr\bin") is included in the PATH environment variable for your user account. But perhaps you are running the gitlab-runner in the system account, which might not have the same PATH.
So the first thing to do is just check your system's PATH variable and add the bin directory if necessary (i.e. using the System applet in the Control Panel as described here or here). Just make sure you restart your machine after you make the change, because the change isn't applied until after you restart. That should make bash work, even when called from a service running in the system or admin account.
As for the strange error you got after creating bash.cmd, that was due to the second issue. Paths are often really hard to get right when combining bash and Windows. Gitlab-runner is probably trying to determine whether the build path is relative or absolute, and ends up prepending the windows path with what it thinks is the working directory ($PWD). This looks like a bug, but gitlab still has not fixed it (as of version 9.0 of the runner!!) and probably never will. Maybe they have decided it is not a bug or that it is due to bugs in underlying software or tools that they can't fix or that it would be too difficult to fix. Anyway, I've discovered a work-around. You can specify the base path for builds in the config.toml file. If you use a unix-style path, it fixes the problem.
On windows, config.toml is usually in the same folder as your gitlab-runner.exe (or gitlab-multi-runner-amd64.exe etc). Open that file in your favorite text editor. Then find the [[runners]] section and add two lines similar to the following.
builds_dir="/c/gitlab-runner/builds/"
cache_dir="/c/gitlab-runner/cache/"
The path you use should be the "bash version" of whatever directory you want gitlab-runner to use for storing builds etc. Importantly if you are using cygwin, you would use a path similar to /cygdrive/c/... instead of just /c/... (which is appropriate for msys-git or standalone MSYS2 etc).
Here's an example of a config.toml file:
[[runners]]
name = "windows"
url = "https://your.server.name"
token = "YOUR_SECRET_TOKEN"
executor = "shell"
shell = "bash"
builds_dir="/c/gitlab-runner/builds/"
cache_dir="/c/gitlab-runner/cache/"
It looks like you're attempting to link gitlab-ci up with the Windows Subsystem for Linux (which can be accessed by typing bash at the Windows command prompt)? I doubt that this is supported directly by Gitlab's runner configuration.
Instead, I would suggest using Powershell with your shell executor.
Executor = 'shell'
Shell = 'powershell'
You can then drop down into Bash in the scripts you call from .gitlab-ci.yml.
Given that it's bad practice to execute more than very trivial shell scripts within the .gitlab-ci.yml itself (as opposed to calling out to an external script), you lose little by being forced to use a native Windows shell.

Where is jython jar located in webspehere application server home directory

I want to write a CGI script for Jython for websphere application server task. The CGI script required shebang where in I need to give jython file path. I have WAS 8.5 and I couldnt fine the jython jar anywhere . where in Jython jar in WAS home directory.
Your cgi script would have to invoke jython scripts from wsadmin, as in the following example.
wsadmin -lang jython -f 'c:/temp/script/test1.py'
It would be best to call specific files from within a script, rather than just simply command line arguments. Keep in mind that each time you invoke wsadmin from within a script it will fire up a separate JVM, which can be very cpu intensive. So it is best to put most logic in external scripts and then call the few .py scripts separately from inside the cgi script.
wsadmin is located in
profiles/<profile_name>/bin
Rerefence:
Jython Infocenter Info

Chef Powershell Run from File

Using chef's powershell_script provider how would I reference a file stored on the chef server instead of having the code defined in the same file? Basically how can I call on a .ps1 located on the server from a chef client?
You can call unsigned powershell scripts directly within powershell_script, as long as your execution policy allows it, which Chef does by default.
powershell_script "run some script" do
code "c:/something/script.ps1"
end
If you want chef to deploy the script too, you can do it from the /files section of the cookbook with cookbook_file.
For multiple lines of code , dont forget to add \n at the end of each line in powershell_script resource's code parameter.

Resources