i am trying to install sql server 2012 using chef to a virtual box.. Below is the code that i use but i am getting source does not exist error. Below is the server.rb code that i have..
package package_name do
source 'C:\Users\user\AppData\Local\Temp\SQLServer2012SP4KB4018073x64ENU.exe'# package_url
checksum package_checksum
timeout node['sql_server']['server']['installer_timeout']
installer_type :custom
options "/q /ConfigurationFile=#{config_file_path} #{passwords_options}"
action :install
notifies :request_reboot, 'reboot[sql server install]'
returns [0, 42, 127, 3010]
Error
* template[C:\Users\vagrant\AppData\Local\Temp\kitchen\cache\ConfigurationFile.ini] action create (up to date)
windows_package[SQLServer2012SP4KB4018073x64ENU.exe] action install
* Source for package SQLServer2012SP4KB4018073x64ENU.exe does not exist
Aside from making the file accessible for windows_package resource, one more change can be made.
The name of windows_package resource should match the application name displayed in Control Panel. As you are using SQLServer2012SP4KB4018073x64ENU.exe as the name, Chef will start installation of the package every time it is run (which is probably not what we want).
For e.g. if I want to install a simple package like WinSCP, which is displayed in Control Panel as WinSCP <version>, then I should name my resource with that.
windows_package 'WinSCP 5.17.7' do
source 'C:\Users\Administrator\Downloads\WinSCP-5.17.7-Setup.exe'
installer_type :custom
options '/silent'
end
Now if Chef runs again, it will make this install idempotent.
Related
Background: our systems are setup in a way that I will only be able to see the local chef log and will have no access to the Chef server console or any other sysadmin privileges. Hence I have a need to log locally if I want to see if or why something failed.
I can hear you asking " If you don't trust the pkg or Chef to install it correctly, then..." My answer is that while you are correct, I still want to be covered by the occasional anomaly.
My goal is to install a pkg, check to see that it installed correctly than go on to the next pkg.
On to the question:
I would like to set a variable that checks for the existence of a directory that was created by the first package using the following code:
mycond = ::File.directory?('/opt/MyPkg/conf')
Chef::Log.fatal("MyPkg package not installed ? conf dir is missing") unless mycond
the next stage in the recipee is to run the next install block checking to see if the variable has been set.
yum_package 'OtherPkg' do
action :install
only_if { mycond }
end
My question is since the only_if is failing, I was wondering if there was something wrong with the way I am setting the mycond variable ? perhapes {} braces are needed somewhere in the code ?
Total Chef newbie so please be specific with your answer.
Thanks !
Full code below:
yum_package 'MyPkg' do
flush_cache [ :before ]
action :install
end
mycond = ::File.directory?('/opt/MyPkg/conf')
Chef::Log.fatal("MyPkg package not installed ? conf dir is missing") unless mycond
yum_package 'OtherPkg' do
action :install
only_if { mycond }
end
The problem is Chef's two-pass model. See https://coderanger.net/two-pass/ for the full explanation for for this you just need to move the condition check in to the only_if block itself since that is delayed until converge time: only_if { ::File.directory?('/opt/MyPkg/conf') }.
Using the fatal log level is also probably not a good idea as this isn't actually a fatal error as written.
Chef has an order of precidance that controls the flow of execution.
Code inside resource blocks (e.g. 'yum_package') will execute AFTER any loose code in your recipe.
The following lines are being executed FIRST, before your 'yum_package' blocks:
mycond = ::File.directory?('/opt/MyPkg/conf')
Chef::Log.fatal("MyPkg package not installed ? conf dir is missing") unless mycond
I believe you can nest resource blocks. You cold be able to combind all this code in a 'ruby_block' and it should execute in order as you'd expect.
eg.
remote_file '/app/abc/' + '/app.rpm' do
source "https://location.com/app.rpm"
end
package 'app.rpm' do
source '/app/abc/app.rpm'
end
file '/app/abc/app.rpm' do
action :delete
end
This is how I am currently deleting the rpm file. Is there a better way to write the code, without having to include the file resource again ?
We generally recommend not deleting so you can use the file for idempotence checks, using a notification to run the package install if the remote file changes.
I'm installing an exe using chef's package resource and the run is failing with a return code of 3010. A return code of 3010 means the install was successful, but a reboot is required.
I can get around this by putting ignore_failure true on the resource, but I think this would let legitimate errors go through.
Chef's resource windows_package has a returns property which allows you to specify an array of possible return values. However, windows_package is deprecated in favor of the more generic package resource, but package does not have a returns property.
Is there some other way that I'm not aware of that would allow me to specify return codes with the generic package resource?
Current code structure:
package 'Install Something' do
source source_location
package_name name_of_package
options argument_list
action :install
provider Chef::Provider::Package::Windows
ignore_failure true
end
It is not deprecated, use windows_package.
Problem is that chef tries to install template first, and only then installs packages. If i comment template block, chef will install sphinxsearch package fine.
But if template block is not commented, sphinxsearch package is not installed, and chef fails with error
resource template[/etc/sphinxsearch/sphinx.conf] is configured to notify resource service[sphinxsearch] with action reload, but service[sphinxsearch] cannot be found in the resource collection`
Why this happens?
##
# Install system packages
##
node['website']['packages'].each do |pkg|
log 'Installing ' + pkg
package pkg
end
##
# Configure sphinx
##
template "/etc/sphinxsearch/sphinx.conf" do
source 'sphinx.erb'
owner 'root'
group 'root'
mode 00644
notifies :reload, 'service[sphinxsearch]', :delayed
end
notifies and subscribes in chef are both trying to reach out to resources that have been defined in your chef run. They will then call teh indicated action on those resources. In your case:
notifies :reload, 'service[sphinxsearch]', :delayed
is looking for a resource of type service named sphinxsearch and call the reload action on it. If, at the end of the resource gathering (compile) phase, chef cannot find a service[sphinxsearch] resource, then it throws the error. You don't see the package installed because chef never enters the execution phase. (See this answer for more on the two phase nature of chef)
As indicated by #IsabelHM, you could solve the problem by adding
service 'sphinxsearch' do
action [:enable, :start]
end
I suggest you use [:enable, :start] rather than :nothing as this will ensure that the service is always running, even if your template doesn't change. Also, please note that the service resource does not add a service config for you. So if the sphinxsearch package does not add a service config, you'll also need a cookbook_file, template, or remote_file resource to create the service config with.
Add this in your recipe.
service 'sphinxsearch' do
action :nothing
end
I'm wrapping my usage of the Opscode Java cookbook with one for my company.
I've created an attributes\default.rb file with values specific to my usage.
Despite including a value for the windows package, I keep getting the following error:
NoMethodError
-------------
No resource or method named `windows_package' for `Chef::Recipe "windows"'
Here is my attributes\default.rb file:
default[:java][:install_flavor] = "windows"
default[:java][:jdk_version] = "7"
default[:java][:windows][:url] = "http"
default[:java][:windows][:package_name] = "Java VM"
I am certain that I have uploaded the updated cookbook to my server, and I am certain that the attributes in this file are being loaded as I was previously receiving errors about missing the required windows package URL until I added it (path edited out above).
In the windows recipe of the Java cookbook, there is a call to the windows_package provider of the windows Cookbook. Thus, the windows cookbook is required for the Java cookbook at least on your platform.
As the Java cookbook doesn't explicitly depend on the windows cookbook (through the metadata.rb), it fails at this late stage.
The solution is to add the windows cookbook to your run list.