2

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
Casper
  • 33,403
  • 4
  • 84
  • 79
Sameer kumar
  • 31
  • 1
  • 3
  • 1
    As the answer(s) point out, its a permissions issue. You are trying to create a file in root (`/`) directory. Does the user with which you are running `chef-client` have permission to create file in this path? – seshadri_c Mar 09 '22 at 06:05

3 Answers3

1

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

Moussa
  • 461
  • 4
  • 14
1

it seems you are not executing this as a root user, change it to root by typing sudo su then rerun the command, hopefully this will help.

I was facing the same issue and stuck for an hour, just did it and succeeded.

Syed Zaka
  • 11
  • 2
0

Errno::EACCES Means "Permission Denied"

The Errno class is mapped to your system call errors at runtime. You can find this (confusingly) documented in:

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

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199