Chef Powershell Run from File - windows

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.

Related

WIX - Executing python file inside installer without moving to INSTALLDIR

as the title says, is it possible to execute a python script inside the installer without having it copied to the installdir and then executing it throught a CustomAction?
I have a config script which is used during install and unninstall but currently i'm copying it to the installdir and then executing it, but I wish I could just execute it without copying...
Thanks
There is no current support for running a python script like there is for vbscript that I know of as Setin Asmul noted in his comment.
There are some convoluted ways of running a custom action and directly extracting a binary out of the MSI database and executing it but a simpler way would be to just make a custom action dll and include the script in the self-extracting package created during the build process.
You can use the CustomActionContents property to include your python script as a file needed by the custom action dll. When you run your custom action the CA.dll package is extracted into a temporary location and the custom action is run. Since the python script was added as a CustomActionContents file it will be in the same temporary dir as the custom action dll so you can run it from there.

How to run bat file in jenkins

My jenkins is installed in C:\Program Files (x86)\Jenkins
bat file is located in C:\Users\Admin\workspace\demoWork\run.bat
When i run this bat file from cmd everything works fine. But when i try from jenkins executing batch command as mentioned in Image, Jenkins displays error as
Build step 'Execute Windows batch command' marked build as failure
Also inside jenkins folder automatically workspace folder gets created with Job title name. Can you guys please explain me in detail
Tatkal, you can't execute a command like in your image,
why don't you simply try
C:\users\admin\workspace\demowork\run.bat
or
call "C:\users\admin\workspace\demowork\run.bat"
"Also inside jenkins folder automatically workspace folder gets created with Job title name. Can you guys please explain me in detail" -
Jenkins creates folder with job title name automatically, saves jobs data and other build info... this is how it works. By default in jenkins job you can access your workspace using $WORKSPACE variable
You have put very little detail into this so I'm going by pure guess..
The Execute Windows batch command is to literally execute code, not execute a file.. to execute the file you could use this command :
start cmd.exe /c C:\myprj\mybat.bat
or you could take the contents of the .bat file and rewrite in in that command line..
The way Jenkins works is it creates its own workspace for each job, essentially to sandbox the environment, its a testing framework so it should be used to stage changes to code, which will then be pushed to your live(working) environment. People use it to automate some tasks, but this isnt the primary use of Jenkins.. if the above doesn't help you let me know more details of the error and I can try help you with it.
node {
bat 'D:\\gatling-charts-highcharts-bundle-3.0.2\\bin\\gatling.bat'
}

Is there any way to run PowerShell scripts in Serverspec?

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?

Chef execute fails for the first time

I have a weird problem with a Chef Recipe. Let me tell you that I'm new to Chef so pardon me if something looks awfully wrong.
I have my war file, which is built by Spring Boot. I just need to run java -jar <file>.war -config=config/ to run my app.
I recently started experimenting with Chef, and getting to write recipes that do this job.
The code from my recipe is as follows:
#Some code has been omitted intentionally.
directory "#{home}" do
owner 'root'
group 'root'
mode '0755'
recursive true
end
directory "#{home}/config" do
owner 'root'
group 'root'
mode '0755'
end
cookbook_file "#{home}/config/ehcache.xml" do
source "ehcache.xml"
mode "0644"
end
# Get the war file from the repo
remote_file "#{home}/app.war" do
source "#{node['baseos']['files_repo_url']}/wars/app.war"
owner 'root'
group 'root'
mode '0644'
end
execute 'Run the war file' do
command "java -jar '#{home}/app.war' -config='#{home}/config/'"
action :run
end
The war file, and the related config folder along with its contents are successfully being copied to their respective destinations before the execute command gets fired. The problem is when the machine gets freshly created with kitchen create, the first kitchen verify would fail, saying 'Errno::ENOENT: No such file or directory - java -jar /opt/com/app.war -config=config/'.
This only happens for the first time. Surprisingly, after saying kitchen verify again, the app starts up, and successfully runs.
This is weird because of the fact that the required file app.war and the config/ are [or should be] already there in the machine with appropriate privileges.
I know Chef processes these things sequentially, so given that the execute command is the very last line in my recipe, it should already have what is required to run the war file. I'm going nuts, can anyone provide some insight into this one?
Thank you!
While it is somewhat counter-intuitive, this is probably because you don't have java available on your $PATH. This might mean java is not installed, or that it is installed but not in a way that Chef can find it. Remember that environment variables are only inherited when a process starts, so if you installed Java in such a way that the installer set up some global change to $PATH it wouldn't be visible to Chef. A good fix would be to use the full path to the JVM binary (/opt/whatever/bin/java or something).

How to get the path to the puppet.conf in a ruby script

I want to write a ruby script that is called from command line.
The script needs to load a configuration from a yaml file. The yaml file is in the Folder of the puppet.conf.
In an custom function of puppet I can get the folder with
File.dirname(Puppet.settings[:config])
Unfortunately "Puppet" is unknown for the script.
Is it possible to load "Puppet" in the script or to get this path in any other way?
---EDIT---
I forgot to mention that this script runs on a puppetmaster and not on a puppetagent. Maybe that matters...
You could probably load the Puppet library by calling
require 'puppet'
before calling Puppet.

Resources