Creation of folder in windows using chef - ruby

Code:
directory node['soft_packname']['source_path'] do
action :create
recursive true
end
Attribute :
default['soft_packname']['source_path'] = 'C:\nscpsource'
But I am an error when I run chef-client on this resource/recipe.
Chef Client failed. 0 resources updated in 08 seconds
[2018-04-06T18:10:54+05:30] FATAL: Stacktrace dumped to c:/opscode/chef-repo/.chef/local-mode-cache/cache/chef-stacktrace.out
[2018-04-06T18:10:54+05:30] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-04-06T18:10:54+05:30] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

Related

How to resolve permission denied # rb_sysopen

I am writing a simple recipe to create file like:
file '/myfile' do
content 'Welcome to Technical Guftgu'
action :create
end
but on chef-client -zr "recipe[test::recipe1]"
i am getting the following error:
[2022-03-08T10:54:16+00:00] ERROR: Running exception handlers
Running handlers complete
[2022-03-08T10:54:16+00:00] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 02 seconds
[2022-03-08T10:54:16+00:00] FATAL: Stacktrace dumped to /home/vagrant/.chef/local-mode-cache/cache/chef-stacktrace.out
[2022-03-08T10:54:16+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2022-03-08T10:54:16+00:00] FATAL: Errno::EACCES: file[/myfile] (test::recipe1 line 7) had an error: Errno::EACCES: Permission denied # rb_sysopen - /myfile
It seems that your app does not have access to the file /myfile.
Try this, to allow access to all: sudo chmod a+rw /myfile
Errno::EACCES Means "Permission Denied"
The Errno class is mapped to your system call errors at runtime. You can find this (confusingly) documented in:
SystemCallError#errno
Errno
In particular:
Errno.constants.include? :EACCES
#=> true
on most *nix sytems Errno::EACCES maps to the libc error code for "permission denied". Specifically:
Macro: int EACCES
"Permission denied." The file permissions do not allow the attempted operation.
That generally means your #create action doesn't have permissions to read, write, or traverse the path to the file you are trying to manage, so you need to change your implementation (which you don't show in your original post) to ensure that your Ruby process has the needed file or filesystem permissions to perform the requested operations.
See Also
Understanding Ruby's strange "Errno" exceptions
errno Lookup
errno.h from The Open Group Base Specifications Issue 7, 2018 edition

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

NoMethodError Unable to Solve

Unable to solve this error when it state NoMethodError
Recipe Compile Error in /var/chef/cache/cookbooks/jbosseap/recipes/default.rb
NoMethodError
-------------
No resource or method named jboss for `Chef::Recipe "default_deploy_list"'
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/jbosseap/recipes/default_deploy_list.rb:1:in from_file
/var/chef/cache/cookbooks/jbosseap/recipes/default.rb:15:in from_file
> Relevant File Content:
>/var/chef/cache/cookbooks/jbosseap/recipes/default_deploy_list.rb:
> 1 jboss 'testweb' do
> 2: source "https://s3-us-west-2.amazonaws.com/chef.repos/testweb.zip"
>3: action :deploy
>4: end
What should I do?
What is jboss in that recipe? You are likely missing a dependency in your metadata.rb file. Chef doesn't know anything about a jboss['testweb'] resource that you're declaring.

FATAL: Errno::EACCES when trying to copy files using Ruby and Chef

I've confirmed that I have permissions on the local box. Here is my default.rb in my Chef cookbook:
ruby_block "Copy Oracle Files" do
block do
require 'fileutils'
FileUtils.cp_r("#{node["server_files"]}","c:\\chef-tmp")
end
action :create
end
Here is the server_files dir: default["server_files"] = "\\\\winmomfs1\\3rdParty\\Oracle Client\\Oracle_11g\\win64_11gR2_client.zip"
And upon running chef-client on the node, I get:
[2013-12-20T12:51:45-05:00] INFO: Running queued delayed notifications before re-raising exception
[2013-12-20T12:51:45-05:00] ERROR: Running exception handlers
[2013-12-20T12:51:45-05:00] ERROR: Exception handlers complete
[2013-12-20T12:51:45-05:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-12-20T12:51:45-05:00] FATAL: Errno::EACCES: ruby_block[Copy Oracle Files] (oracle::default line 9) had an error: Errno::EACCES: Permission denied - \\winmomfs1\3rdParty
\Oracle Client\Oracle_11g\win64_11gR2_client.zip
Any ideas why?

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