0

I know that you can run the 'execute' module in Chef recipes and that it contains a cwd and user parameter that will allow you to run a command as that user in the current working directory. Which is what I have done in my code:

execute 'rpmdev-setuptree' do
   user 'rpmbuild'
   cwd '/home/rpmbuild'
   live_stream true
   action :run
end

I have been doing different variations of executing this command as root or explicitly changing the directory (i.e execute 'cd /home/rpmbuild && rpmdev-setuptree), but that doesn't work. Chef seems pretty determined to run this command in the /root directory no matter what I do. Why is this happening? Please note, I have been doing:

execute 'cd /home/rpmbuild  && rpmdev-setuptree' do
   user 'rpmbuild'
   cwd '/home/rpmbuild'
   live_stream true
   action :run
end

Or

execute 'sudo su - rpmbuild  && rpmdev-setuptree' do
   user 'root'
   cwd '/home/rpmbuild'
   live_stream true
   action :run
end 

Can someone tell me why this occurs? I am trying to run rpmdev-setuptree in the /home/rpmbuild directory so that it builds the paths out but its ALWAYS running this command in the /root directory.

Output varies between which snippet I ran, some completed with no output. But I didn notice when trying to just rpmdev-setuptree by itself, it would have:

   [execute] touch: cannot touch ‘/root/.rpmmacros’: Permission denied
      grep: /root/.rpmmacros: No such file or directory
      /bin/rpmdev-setuptree: line 43: [: -lt: unary operator expected
      grep: /root/.rpmmacros: No such file or directory
      /bin/rpmdev-setuptree: line 57: [: -lt: unary operator expected
      grep: /root/.rpmmacros: No such file or directory
      /bin/rpmdev-setuptree: line 75: [: -lt: unary operator expected
      mkdir: cannot create directory ‘/root/rpmbuild’: Permission denied
      mkdir: cannot create directory ‘/root/rpmbuild’: Permission denied
      mkdir: cannot create directory ‘/root/rpmbuild’: Permission denied
      mkdir: cannot create directory ‘/root/rpmbuild’: Permission denied
      mkdir: cannot create directory ‘/root/rpmbuild’: Permission denied
ryekayo
  • 2,341
  • 3
  • 23
  • 51

1 Answers1

1

Are you sure the issue is the working dir and not that rpmdev-setuptree is trying to use $HOME for something? For a variety of not very good reasons, we don't automatically set $HOME when running as a different user, so you may have to add environment 'HOME' => '/home/rpmbuild' too.

coderanger
  • 52,400
  • 4
  • 52
  • 75