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