Need to run a Custom chef recipe to be run with sudo priviliges

1k views Asked by At

I have to run a custom chef recipe for creating a directory under /ops, but I do not want to use root user for this. I have a user who has the sudo priviliges to create a directory manually

 sudo mkdir /ops/usr/apps  is working fine manually.

I have my recipe to create a directory as this:

 directory "#{node[:workspace]}" do
   owner "#{node[:user]}"
   mode "0775"
   recursive true
   action :create
 end

Can I simulate something similar to above manual command using sudo for my current user. Thanks in advance for the help.

1

There are 1 answers

0
Mark O'Connor On

Why don't you just run chef solo using sudo?

$ sudo chef-solo -c solo.rb -j solo.json
Starting Chef Client, version 11.4.0
Compiling Cookbooks...
Converging 1 resources
Recipe: demo::default
  * directory[/ops/usr/apps] action create
    - create new directory /ops/usr/apps
    - change mode from '' to '0775'
    - change owner from '' to 'mark'

Chef Client finished, 1 resources updated