Sameer kumar
Sameer kumar

Reputation: 51

How to resolve permission denied @ rb_sysopen

I am writing a simple recipe to create a file:

file '/myfile' do
  content 'Welcome to Technical Guftgu'
  action :create
end

But on chef-client -zr "recipe[test::recipe1]" I am getting the 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

Upvotes: 4

Views: 14203

Answers (3)

Syed Zaka
Syed Zaka

Reputation: 9

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.

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

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

Upvotes: 1

Moussa
Moussa

Reputation: 510

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

Upvotes: 3

Related Questions