VijayVishnu
VijayVishnu

Reputation: 537

Run the chef-client as non root user

I want to run the chef-client as a test user in my linux machine. For that, I add cache path in the client.rb file which is from /etc/chef/client.rb.

cache_path "~/.chef/cache"

Then I run the chef-client command from test user(non-root user).It shows error?

Chef encountered an error attempting to create the client 

How to setup the cache-path? Is is necessary to move the client.rb,chef-validator.pem, client.pem, first-boot.json under test user?

Upvotes: 2

Views: 3942

Answers (1)

Tensibai
Tensibai

Reputation: 15784

First of all, chef is intended to be run as root. A lot of resources assume they're run as root, and need it. They will fail if not running as root.

For your error specifically, your test user has no right to write a file in /etc/chef (default location) and it need to write the client.pem node certificate.

Some ideas:

  1. Give rights on /etc/chef to your test user
  2. use sudo to run chef client with a test user (need an entry in sudoers file)
  3. Modify the client.rb file to point client_key to your test user home directory
  4. Do a first run of chef as root so it can write it's node certificate, then it won't have to write again in /etc/chef

Upvotes: 3

Related Questions