私は OS X 10.9.1 で Ruby 2.1 と Capistrano 3.1 を使用しており、CentOS 6.5 にデプロイしています。
ターゲット展開サーバーでは、展開ユーザーとして ssh できませんが、 としてadmin@myserver
ssh できpaul@myserver
ますsudo su - admin
。
テストタスクを作成しました:
task :sayhello do
on roles(:app) do
as "admin" do
puts capture "whoami"
end
end
end
そして、それは期待どおりに機能します:
$ cap beta deploy:sayhello
DEBUG [acaa0e6a] Running /usr/bin/env if ! sudo su admin -c whoami > /dev/null; then echo "You cannot switch to user 'admin' using sudo, please check the sudoers file" 1>&2; false; fi on awse-tweb01.foo.com
DEBUG [acaa0e6a] Command: if ! sudo su admin -c whoami > /dev/null; then echo "You cannot switch to user 'admin' using sudo, please check the sudoers file" 1>&2; false; fi
DEBUG [acaa0e6a] Finished in 6.982 seconds with exit status 0 (successful).
DEBUG [153b980d] Running /usr/bin/env whoami on awse-tweb01.foo.com
DEBUG [153b980d] Command: sudo su admin -c "/usr/bin/env whoami"
DEBUG [153b980d] admin
DEBUG [153b980d] Finished in 0.535 seconds with exit status 0 (successful).
admin
管理者として Capistrano にデプロイ タスクを実行させるにはどうすればよいですか? つまり、コマンドを実行する前に、sudo su admin -c
またはsudo su
シェルをプレフィックスとして付けます。