Hello Community,
It seems that when using chef-run for adhoc execution of cookbooks/recipes on windows host, they are not executed properly.
Please consider very simple recipe like
file 'c:\\test\\testtest.txt' do
content 'This is a test file'
rights :full_control, 'administrator'
action :create
end
Now, I run the cookbook like
chef-run myhost mysimplebook/ --user Administrator --password AB12cd34 --protocol winrm
Nothing happens on target machine. No file is created.
If I add cookbook to server run-list in Infra Server, it is correctly picked up by chef-client and executed. File is created.
What is the reason for this? Is this bug or feature, please?
when running the chef-run command are you in the mysimplebook directory or in it's parent directory? When using chef-run and specifying a cookbook you either have to give it the full path or it'll look for a folder by the name of the cookbook in the current working directory or in a directory specified in your knife config.rb cookbook_paths option.
Hello, I am in directory with all cookbooks.
Execution looks like on attached image. It should be executed correctly.
Full code of recipe in question:
#
# Cookbook:: windows_install_MSSQL_powershell_DSC
# Recipe:: default
#
# Copyright:: 2023, The Authors, All Rights Reserved.
powershell_script 'Prepare Machine for DSC' do
code <<-EOH
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
Install-Module -Name SqlServerDsc
Install-Module -Name SqlServer
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
EOH
end
file 'c:\\test\\testtest.txt' do
content 'This is a test file'
rights :full_control, 'WINDOMAIN.pavel\\administrator'
action :create
end
cookbook_file 'c:\\test\\create_mof_file.ps1' do
source 'create_mof_file.ps1'
action :create
end
Thank you for your time. I will follow up on github