Unable to install packages using chef - windows

Error executing action `install` on resource 'windows_package[autologon]'
================================================================================
Chef::Exceptions::CannotDetermineWindowsInstallerType
-----------------------------------------------------
Installer type for Windows Package 'autologon' not specified and cannot be determined from file extension 'exe'
Resource Declaration:
---------------------
# In C:/Users/kitchen/AppData/Local/Temp/kitchen/cache/cookbooks/rclient/recipes/windows.rb
26: windows_package 'autologon' do
27: source "#{node['rclient']['remote_root_url']}/autologon/3.10/Autologon.exe"
28: end
29:
Also same issue for IEDriverServer.exe and msys2-x86_64-20161025.exe packages.

See https://docs.chef.io/resource_windows_package.html for information. You almost certainly need to specify :installer_type.
https://github.com/chef/chef/blob/master/lib/chef/provider/package/windows.rb#L91 is the method where the error you see is being produced.

Related

Chef - Installing a Windows Package from a Mapped Drive

I am trying to install a package from a mapped drive. However, chef says my source path is an invalid location even though I know it is the correct location. Do I need to map the drive first, before Chef recognizes the source path? I looked online in a couple places and could not find an answer.
case node['platform']
when 'windows'
windows_package 'QualysCloudAgent' do
source '\\Server#\Location1\Qualys_agent\QualysCloudAgent.exe'
options '-argumentlist "CustomerId={etc...etc...etc..} ActivationId={etc...etc..etc...}"'
installer_type :custom
action :install
end
end
The error that I get when the chef client runs is that the source location is in invalid source, even though I can get to the source location by typing it in on the server itself. Any help would be appreciated. Thank you. Error That I receive is below.
* Source for package QualysCloudAgent does not exist
================================================================================
Error executing action `install` on resource 'windows_package[QualysCloudAgent]'
================================================================================
Chef::Exceptions::Package
-------------------------
Source for package QualysCloudAgent does not exist
Resource Declaration:
---------------------
# In c:/chef/cache/cookbooks/qualys/recipes/qualys_configure.rb
18: windows_package 'QualysCloudAgent' do
19: source '\\Server#\Location1\Qualys_agent\QualysCloudAgent.exe'
20: options '-argumentlist "CustomerId={etc...etc...etc...} ActivationId={etc...etc...etc...}"'
21: installer_type :custom
22: action :install
23: end
24: end
Compiled Resource:
------------------
# Declared in c:/chef/cache/cookbooks/qualys/recipes/qualys_configure.rb:18:in `from_file'
windows_package("QualysCloudAgent") do
package_name "QualysCloudAgent"
action [:install]
default_guard_interpreter :default
declared_type :windows_package
cookbook_name "qualys"
recipe_name "qualys_configure"
source "p:\\Server#\\Location1\\qualys_agent\\qualyscloudagent.exe"
options "-argumentlist \"CustomerId={etc...etc...etc...} ActivationId={etc...etc...etc...}\""
installer_type :custom
end
System Info:
------------
chef_version=14.14.25
platform=windows
platform_version=6.3.9600
ruby=ruby 2.5.7p206 (2019-10-01 revision 67816) [x64-mingw32]
program_name=C:/opscode/chef/bin/chef-client
executable=C:/opscode/chef/bin/chef-client
2020-01-12T22:21:50-08:00] INFO: Running queued delayed notifications before re-raising exception
unning handlers:
2020-01-12T22:21:50-08:00] ERROR: Running exception handlers
unning handlers complete
2020-01-12T22:21:50-08:00] ERROR: Exception handlers complete
hef Client failed. 0 resources updated in 14 seconds
2020-01-12T22:21:51-08:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
2020-01-12T22:21:51-08:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
2020-01-12T22:21:51-08:00] FATAL: Chef::Exceptions::Package: windows_package[QualysCloudAgent] (qualys::qualys_configur
line 18) had an error: Chef::Exceptions::Package: Source for package QualysCloudAgent does not exist
Since you're installing a package, it's safe to assume you are running chef-client with elevated permissions. Any network drives you map that are visible in Explorer, will not be usable in an elevated process. You will either need to:
Use the UNC path in place of a letter drive
Map the drive during the Chef run (required if the full UNC path would exceed 255 characters)
If you opt for the latter approach, you can use the mount resource to map a network drive.

How to resolve Chef TypeError: "no implicit conversion of String into Integer" using node.normal?

I'm currently testing a new chef cookbook for Zabbix monitoring, and had my first successful 'chef' using this cookbook. I was, however, forced to make a change to one of the attributes, because it will change from server to server. I decided to use a data bag, and I'm having difficulty retrieving and assigning the attribute.
Here are the contents of the data bag:
[user#workstation chef-repo]# knife data bag show zabbix_psk psk_syslog
WARNING: Unencrypted data bag detected, ignoring any provided secret options.
id: psk_syslog
psk: PSK 060
I did not assign the attribute in the attributes file, but rather in the recipe:
default.rb
keyvalue = data_bag('zabbix_psk')
node.normal['zabbix_agentd']['psk_number'] = keyvalue['psk_syslog']['psk']
And then I assign it in a template:
TLSPSKIdentity=<%= node['zabbix_agentd']['psk_number'] %>
When I attempt to Chef, I receive the following error and dump:
TypeError
---------
no implicit conversion of String into Integer
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/zabbix_agentd/recipes/default.rb:28:in `[]'
/var/chef/cache/cookbooks/zabbix_agentd/recipes/default.rb:28:in `from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/zabbix_agentd/recipes/default.rb:
21: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22: # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24: # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25: # THE SOFTWARE.
26:
27: keyvalue = data_bag('zabbix_psk')
28>> node.normal['zabbix_agentd']['psk_number'] = keyvalue['psk_syslog']['psk']
29:
30: case node['platform']
31: when 'centos', 'redhat'
32: include_recipe 'zabbix_agentd::yum_repo'
33: end
34:
35: package 'zabbix-agent'
36:
37: directory node['zabbix_agentd']['log_dir'] do
System Info:
------------
chef_version=13.6.0
platform=centos
platform_version=7.4.1708
ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
program_name=chef-client worker: ppid=11127;start=14:18:48;
executable=/opt/chef/bin/chef-client
Running handlers:
[2017-12-14T14:18:56-06:00] ERROR: Running exception handlers
Running handlers complete
[2017-12-14T14:18:56-06:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 07 seconds
[2017-12-14T14:18:56-06:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2017-12-14T14:18:56-06:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-12-14T14:18:56-06:00] ERROR: no implicit conversion of String into Integer
[2017-12-14T14:18:56-06:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
I'm having difficulty understanding what's wrong with the node.normal assignment in default.rb. I'm new to both Chef and Ruby, so I really appreciate the help. I should also note that I could not use the method get_databag_item; aparently that method did not exist?
data_bag('zabbix_psk') returns an array of the names of the items in the bag, not the data in all the items. You want data_bag_item('zabbix_psk', 'psk_syslog') instead, and then adjust your usage of the value returned.

Chef LWRP recipe Errno::ENOENT: No such file or directory # dir_s_mkdir

I am using the chef community java cookbook to install java on CentOS 7.2. I have an LWRP recipe that is not working
I build up my install parameters via the java_ark section
op_sys = node['os']
# Used to get the required java update from the environment file
java_ver_update = node['java_ver']
# Logic for each OS
if op_sys == 'linux'
# Java_ark, which is used to define the correct install attributes for each OS type (win/linux)
install_dir = node['install_dir']
java_ark "jdk" do
url 'http://sv-dc01.sv.local/install_artifacts/java/oracle/JRE/jre-'+"#{java_ver_update}"+'-linux-x64.tar.gz'
app_home install_dir
owner 'root'
group 'wheel'
app_home_mode 774
action :install
end
# Set the folder permissions
execute "chown-dir" do
command "chmod -R 774 #{install_dir}"
action :run
end
end
Here is my environment file where I have set some node attributes to be called in the main recipe
name 'env_workstation_dubbo'
description "Environment Workstation Dubbo"
cookbook_versions({
"ohai" => "> 0.0.1",
"java" => "> 0.1.0",
"install_java" => "> 0.0.1"
})
$environment = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }
$override = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }
$override['java']['jdk_version'] = '8'
$override['java']['install_flavor'] = 'oracle'
$override['java']['oracle']['accept_oracle_download_terms'] = true
$override['java']['set_default'] = false
# Custom attributes/variables to be placed here
$override['java_ver'] = '8u77'
$override['install_dir'] = '/applications/'
default_attributes(Chef::Mixin::DeepMerge.merge($_default_environment, $environment))
override_attributes($override)
And here is what happens during the sudo chef-client run on the CentOS machine I am using for testing:
Starting Chef Client, version 12.16.42
resolving cookbooks for run list: ["install_java"]
Synchronizing Cookbooks:
- install_java (0.2.0)
- java (1.43.0)
- compat_resource (12.16.2)
- ohai (4.2.2)
- seven_zip (2.0.2)
- homebrew (2.1.2)
- apt (5.0.0)
- build-essential (7.0.2)
- windows (2.1.1)
- mingw (1.2.4)
- ark (2.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
[2016-12-12T11:04:24+13:00] WARN: Chef::Provider::AptRepository already exists! Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
[2016-12-12T11:04:24+13:00] WARN: AptRepository already exists! Deprecation class overwrites Custom resource apt_repository from cookbook apt
Converging 8 resources
Recipe: install_java::default
* java_ark[jdk] action install
================================================================================
Error executing action `install` on resource 'java_ark[jdk]'
================================================================================
Errno::ENOENT
-------------
No such file or directory # dir_s_mkdir -
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/java/providers/ark.rb:116:in `block (2 levels) in class_from_file'
/var/chef/cache/cookbooks/java/providers/ark.rb:115:in `block in class_from_file'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/install_java/recipes/default.rb
18: java_ark "jdk" do
19: url 'http://sv-dc01.sv.local/install_artifacts/java/oracle/JRE/jre-'+"#{java_ver_update}"+'-linux-x64.tar.gz'
20: app_home install_dir
21: owner 'root'
22: group 'wheel'
23: app_home_mode 774
24: action :install
25: end
26:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/install_java/recipes/default.rb:18:in `from_file'
java_ark("jdk") do
action [:install]
supports {:report=>true, :exception=>true}
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :java_ark
cookbook_name "install_java"
recipe_name "default"
url "http://sv-dc01.sv.local/install_artifacts/java/oracle/JRE/jre-8u77-linux-x64.tar.gz"
app_home "/applications/"
owner "root"
group "wheel"
app_home_mode 774
end
Platform:
---------
x86_64-linux
Running handlers:
[2016-12-12T11:04:25+13:00] ERROR: Running exception handlers
Running handlers complete
[2016-12-12T11:04:25+13:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 17 seconds
[2016-12-12T11:04:25+13:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-12-12T11:04:25+13:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-12-12T11:04:25+13:00] ERROR: java_ark[jdk] (install_java::default line 18) had an error: Errno::ENOENT: No such file or directory # dir_s_mkdir -
[2016-12-12T11:04:25+13:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
I can't for the life of me figure out why it can't find the file or directory or get a completed install of Java working???
Maybe your environment is not applied correctly. I mean, if you machine is not using your 'env_workstation_dubbo' environment, the node['install_dir'] attribute will not be correctly set. You can read how to set the environment for a node here.
Another possibility is that you are using a modified version of the java cookbook that uses mkdir instead of mkdir_p. I say that because I have not been able to find your 2.0.0 java cookbook version in the supermarket. Where are you getting that cookbook from?
Update after downgraded to java cookbook version v1.43.0
The problem is that the install_dir must be at least 2 directory level deep, following the app_root/app_name format. For example "/applications/default".
If you use "/applications" as install_dir, app_name will be "applications", app_root will be empty and the latter will cause the mkdir error when trying to create the application root directory.

Unable to set jdoconfig.xml and appname.properties templates for the war file deployed in tomcat7/webapps

Recipe:
include_recipe "lgjava"
include_recipe "lgtomcat"
remote_file "/usr/local/tomcat7/webapps/web.war" do #this file places web.war in the specified path
source "http://path/to/web.war"
action :create_if_missing
end
template "jdoconfig.xml" do
source "jdoconfig.xml.erb"
path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
action :create_if_missing
mode "0755"
end
template "appname.properties" do
source "appname.properties.erb"
path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/appname.properties"
action :create_if_missing
mode "0755"
end
Execution:
Recipe: lgwebapp::default
* remote_file[/usr/local/tomcat7/webapps/web.war] action create_if_missing
- create new file /usr/local/tomcat7/webapps/web.war
- update content in file /usr/local/tomcat7/webapps/web.war from none to ac4b77
(file sizes exceed 10000000 bytes, diff output suppressed)
- restore selinux security context
* template[jdoconfig.xml] action create_if_missing
* Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.
================================================================================
Error executing action `create_if_missing` on resource 'template[jdoconfig.xml]'
================================================================================
Chef::Exceptions::EnclosingDirectoryDoesNotExist
------------------------------------------------
Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/lgwebapp/recipes/default.rb
20: template "jdoconfig.xml" do
21: source "jdoconfig.xml.erb"
22: path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
23: action :create_if_missing
24: mode "0755"
25: end
26:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/lgwebapp/recipes/default.rb:20:in `from_file'
template("jdoconfig.xml") do
provider Chef::Provider::Template
action [:create_if_missing]
retries 0
retry_delay 2
guard_interpreter :default
path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
backup 5
atomic_update true
source "jdoconfig.xml.erb"
cookbook_name "lgwebapp"
recipe_name "default"
mode "0755"
end
Recipe: lgtomcat::default
* service[tomcat7] action restart
- restart service service[tomcat7]
Running handlers:
[2015-01-14T10:38:44+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-01-14T10:38:44+00:00] ERROR: Exception handlers complete
[2015-01-14T10:38:44+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 6 resources updated in 6.532117395 seconds
[2015-01-14T10:38:44+00:00] ERROR: template[jdoconfig.xml] (lgwebapp::default line 20) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.
[2015-01-14T10:38:44+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
P.S: the web.war file is deployed under tomcat7/webapps and its extracted too. I manually checked it, the file exists in the specific location. Why is that it's not able to locate using 'templates'?
Take it as stream:
Chef deploys the war then renders the template and try to compare with existing file.
The problem is that when chef tries to get the target file info, Tomcat probably has not yet unpacked the war file at all.
We do this kind of deployment with an ark resource out of tomcat, render the templates and then copy or link (depending on the cases) the temp deploy dir to the webapps tomcat dir.
The below code solved my problem:
ruby_block 'wait for tomcat' do
block do
true until ::File.exists?("#{node['webapp']['webinf_dir']}")
end
end

Chef: cannot load such file -- moneta/basic_file

I am running a recipe which I have used a bazillion times before, and im getting these errors when I spin up a new EC2 instance with chef + knife.
[2013-01-30T23:44:48+00:00] INFO: Processing user[dan] action create (/var/chef/cache/cookbooks/users/providers/manage.rb line 65)
[2013-01-30T23:44:48+00:00] INFO: user[dan] created
[2013-01-30T23:44:48+00:00] INFO: Processing directory[/home/dan/.ssh] action create (/var/chef/cache/cookbooks/users/providers/manage.rb line 81)
[2013-01-30T23:44:48+00:00] INFO: directory[/home/dan/.ssh] created directory /home/dan/.ssh
[2013-01-30T23:44:48+00:00] INFO: directory[/home/dan/.ssh] owner changed to 2003
[2013-01-30T23:44:48+00:00] INFO: directory[/home/dan/.ssh] group changed to 2003
[2013-01-30T23:44:48+00:00] INFO: directory[/home/dan/.ssh] mode changed to 700
[2013-01-30T23:44:48+00:00] INFO: Processing template[/home/dan/.ssh/authorized_keys] action create (/var/chef/cache/cookbooks/users/providers/manage.rb line 88)
[2013-01-30T23:44:48+00:00] FATAL: Could not load Moneta back end "BasicFile"
================================================================================
Error executing action `create` on resource 'template[/home/dan/.ssh/authorized_keys]'
================================================================================
LoadError
---------
cannot load such file -- moneta/basic_file
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/users/providers/manage.rb
88: template "#{home_dir}/.ssh/authorized_keys" do
89: source "authorized_keys.erb"
90: cookbook new_resource.cookbook
91: owner u['id']
92: group u['gid'] || u['id']
93: mode "0600"
94: variables :ssh_keys => u['ssh_keys']
95: end
96: end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/users/providers/manage.rb:88:in `block (2 levels) in class_from_file'
template("/home/dan/.ssh/authorized_keys") do
provider Chef::Provider::Template
action "create"
retries 0
retry_delay 2
path "/home/dan/.ssh/authorized_keys"
backup 5
source "authorized_keys.erb"
cookbook "users"
variables {:ssh_keys=>"ssh-rsa <REPLACED BECAUSE SHUTUP>!"}
cookbook_name "users"
mode "0600"
owner "dan"
group "dan"
end
[2013-01-30T23:44:48+00:00] ERROR: Running exception handlers
[2013-01-30T23:44:48+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-01-30T23:44:48+00:00] ERROR: Exception handlers complete
[2013-01-30T23:44:48+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-01-30T23:44:48+00:00] FATAL: LoadError: template[/home/dan/.ssh/authorized_keys] (/var/chef/cache/cookbooks/users/providers/manage.rb line 88) had an error: LoadError: cannot load such file -- moneta/basic_file
I have no idea what is going on, what moneta is, or why it cannot build from that template. The template is in templates/default/authorized_keys.erb as expected.
It's the "moneta" gem, which was recently upgraded. Luckily, there is a simple fix (roll it back!), unless you are using new functionality inside that gem. Perform the following:
gem install moneta --version=0.6.0
gem uninstall moneta
... and then uninstall all versions of moneta >= 0.7.0
Reference chef ticket

Resources