Vagrant + Chef : How to execute a task totally in the context of another user?



After I checked out a git repo, I want to run a python script inside the
repo for a user account ‘abc’. It will install a ‘.project’ file in

Here is how I define the task:

bash “install_project” do

cwd “/home/abc/apps/project”

user "abc"

code <<-EOH

 sudo -u abc python ./


only_if { ::File.exists?("/home/abc/apps/project") }


However it fails with a permission exception:
OSError: [Errno 13] Permission denied: ‘/home/vagrant/.project’

Apparently the command is executed in the context of vagrant

I have tried a few alternative commands, but they all failed with the
permission problem e.g.

$ sudo -u abc -s bash -i -c “/usr/bin/python ./”

Installing “project”…

Traceback (most recent call last):

File “./”, line 67, in

shutil.copytree('template', dest)

File “/usr/lib/python2.7/”, line 177, in copytree


File “/usr/lib/python2.7/”, line 157, in makedirs

mkdir(name, mode)

OSError: [Errno 13] Permission denied: ‘/home/vagrant/.project’

How can I get the “python” to run in the user ‘abc’ session?

Cheers, Tony