Chef: run two recipes with different users in same cookbook -


i have chef cookbook needs call 2 recipes: 1 root, create new user , add /etc/sudoers, , recipe supposed run using newly created user.

i understand can execute commands user using bash resource, in case need call include_recipe in both cases (root , new user).

any ideas?

chef-client runs rootuser , cannot run recipe user.

it legitimate create user , couple of things in name of user, e.g:

user "foo"  directory "/usr/local/foo"   owner "foo" end  execute "install foo"   command "whatever-foo"   user "foo" end 

however, if have recipe want include 2 times , should exact same things, different users (e.g. in home directory), forget idea recipes everything. use custom resource has user property.

then, can call resource 2 times, once every user:

%w{root otheruser}.each |u|   mycookbook_myresource "do-it-for-user-#{u}"     user u   end end 

Comments