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


Chronological Thread 
  • From: Anthony Kong < >
  • To:
  • Subject: [chef] Vagrant + Chef : How to execute a task totally in the context of another user?
  • Date: Sat, 14 Mar 2015 19:57:11 +1100

Hi,

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 /home/abc.

Here is how I define the task:

bash "install_project" do

  cwd "/home/abc/apps/project"

    user "abc"

  code <<-EOH

     sudo -u abc python ./install.py

     EOH

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

end

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 ./install.py" 

Installing "project"...

Traceback (most recent call last):

  File "./install.py", line 67, in <module>

    shutil.copytree('template', dest)

  File "/usr/lib/python2.7/shutil.py", line 177, in copytree

    os.makedirs(dst)

  File "/usr/lib/python2.7/os.py", line 157, in makedirs

    mkdir(name, mode)

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


How can I get the "python install.py" to run in the user 'abc' session?


Cheers, Tony



  • [chef] Vagrant + Chef : How to execute a task totally in the context of another user?, Anthony Kong, 03/14/2015

Archive powered by MHonArc 2.6.16.

§