質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

1回答

2729閲覧

capistrano,「Insecure operation」でbundle installできない

tkkk

総合スコア7

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2016/08/21 15:28

編集2016/08/25 13:06

###前提・実現したいこと
現在Ruby(Ruby On Rails)でアプリケーションを開発しています。
ローカルからリモートサーバーにcapistranoでrailsアプリケーションをデプロイしたいのですが、capistranoの「bundler」のタスクを実行する際に、下記のログの通り、SSHKit::Runner::ExecuteError: Exception while executing as deploy_user@IP_address: bundle exit status: 1 bundle stdout: /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in expand_path': Insecure operation - expand_path (SecurityError)`でbundle installができない状態です。

###エラーログなど

cmd

1.長いため省略しています 2 INFO [5c9a0279] Running sudo rbenv exec bundle install --path /var/www/myapp/shared/bundle --without development test --deployment --quiet as deploy_user@153.126.179.98 3 DEBUG [8c7ee5b1] Command: cd /var/www/myapp/releases/20160821142536 && ( export RBENV_ROOT="/usr/local/rbenv" RBENV_VERSION="2.3.1" ; /usr/local/rbenv/bin/rbenv exec bundle install --path /var/www/myapp/shared/bundle --without development test --deployment --quiet ) 4 DEBUG [8c7ee5b1] /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `expand_path': Insecure operation - expand_path (SecurityError) 5 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `block in which' 6 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `each' 7 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `find' 8 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `which' 9 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:377:in `git_present?' 10 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:54:in `initialize' 11 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `new' 12 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `git_version' 13 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:22:in `report' 14 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for' 15 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:40:in `log_error' 16 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:100:in `rescue in with_friendly_errors' 17 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors' 18 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>' 19 from /usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `load' 20 from /usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `<main>' 21(Backtrace restricted to imported tasks) 22cap aborted! 23SSHKit::Runner::ExecuteError: Exception while executing as deploy_user@IP_address: bundle exit status: 1 24bundle stdout: /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `expand_path': Insecure operation - expand_path (SecurityError) 25 ↑↓ //上のエラーのパスと同じ (from/~の内容) 26bundle stderr: Nothing written 27 28Tasks: TOP => deploy:updated => bundler:install 29(See full trace by running task with --trace) 30The deploy has failed with an error: Exception while executing as deploy_user@IP_address: bundle exit status: 1 31bundle stdout: /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `expand_path': Insecure operation - expand_path (SecurityError) 32 ↑↓ //上のエラーのパスと同じ (from/~の内容) 33bundle stderr: Nothing written 34Admin-Mac:myapp admin$ 35

###deploy.rb

ruby

1set :application, 'myapp' 2set :repo_url, 'git@bitbucket.org:myapp/myapp.git' 3set :puma_threads, [4, 5] 4set :puma_workers, 1 5set :rbenv_ruby, '2.3.1' 6set :rbenv_path, '/usr/local/rbenv' 7set :pty, true 8set :use_sudo, false 9set :stage, :production 10set :deploy_via, :remote_cache 11set :deploy_to, '/var/www/myapp' 12set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" 13set :puma_state, "#{shared_path}/tmp/pids/puma.state" 14set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" 15set :puma_access_log, "#{release_path}/log/puma.error.log" 16set :puma_error_log, "#{release_path}/log/puma.access.log" 17set :puma_preload_app, true 18set :puma_worker_timeout, nil 19set :puma_init_active_record, true # Change to false when not using ActiveRecord 20 21## Defaults: 22set :scm, :git 23set :branch, :master 24set :format, :pretty 25set :log_level, :debug 26set :keep_releases, 6 27 28## Linked Files & Directories (Default None): 29set :linked_files, %w{config/database.yml config/secrets.yml} 30set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} 31 32namespace :deploy do 33 34 desc 'Initial Deploy' 35 task :initial do 36 on roles(:app) do 37 before 'deploy:restart', 'puma:start' 38 invoke 'deploy' 39 end 40 end 41 42 before :starting, :check_revision 43 after :finishing, :compile_assets 44 after :finishing, :cleanup 45 after :finishing, :restart 46end

###試してみたこと

cmd

1[deploy_user@ik1-325-22 ~]$ rbenv version 22.3.1 (set by /usr/local/rbenv/version) 3 4[deploy_user@ik1-325-22 ~]$ bundle version 5/usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `expand_path': Insecure operation - expand_path (SecurityError) 6 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:310:in `block in which' 7 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `each' 8 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `find' 9 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:308:in `which' 10 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:377:in `git_present?' 11 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:54:in `initialize' 12 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `new' 13 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `git_version' 14 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/env.rb:22:in `report' 15 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for' 16 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:40:in `log_error' 17 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:100:in `rescue in with_friendly_errors' 18 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors' 19 from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>' 20 from /usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `load' 21 from /usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `<main>' 22

cmd

1[deploy_user@ik1-325-22 ~]$ sudo bundle version 2Bundler version 1.12.5

以上の内容からsudoをつければいけるのかと思い、deploy.rbset :rbenv_prefix, "sudo rbenv exec”を追記して実行しましたが、下記のエラー内容...

cmd

1. 2.冒頭のログとほぼ同じため省略しています。 3. 4 INFO [5c9a0279] Running sudo rbenv exec bundle install --path /var/www/myapp/shared/bundle --without development test --deployment --quiet as deploy_user@IP_address 5 DEBUG [5c9a0279] Command: cd /var/www/myapp/releases/20160821145425 && ( export RBENV_ROOT="/usr/local/rbenv" RBENV_VERSION="2.3.1" ; sudo rbenv exec bundle install --path /var/www/myapp/shared/bundle --without development test --deployment --quiet ) 6 DEBUG [5c9a0279] An error occurred while installing nio4r (1.2.1), and Bundler cannot continue. 7Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling. 8(Backtrace restricted to imported tasks) 9cap aborted! 10SSHKit::Runner::ExecuteError: Exception while executing as deploy_user@IP_address: bundle exit status: 5 11bundle stdout: An error occurred while installing nio4r (1.2.1), and Bundler cannot continue. 12Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling. 13bundle stderr: Nothing written 14 15Tasks: TOP => deploy:updated => bundler:install 16(See full trace by running task with --trace) 17The deploy has failed with an error: Exception while executing as deploy_user@IP_address: bundle exit status: 5 18bundle stdout: An error occurred while installing nio4r (1.2.1), and Bundler cannot continue. 19Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling. 20bundle stderr: Nothing written 21

###環境
サーバーOS: CentOS6.8
Ruby: 2.3.1
Ruby On Rails: 5.0.0
1つのサーバーにnginx+puma+Railsアプリケーション
リストrbenvを下記のサイトを参考にAnsibleにてシステムワイドにインストールをして実行しています。
http://ria10.hatenablog.com/entry/2015/04/14/132129

かなりはまってしまい自分では解決できそうになかったので投稿させていただきました。どうかよろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

deploy 先のサーバ上で以下のコマンドを実行するとどうなるのでしょうか?

ruby

1$ cd /var/www/myapp/releases/20160821142536 && 2 ( export RBENV_ROOT="/usr/local/rbenv" RBENV_VERSION="2.3.1" ; 3 /usr/local/rbenv/bin/rbenv exec bundle install --path 4 /var/www/myapp/shared/bundle --without development test --deployment --quiet )

※ 適当に折り返してます。

$SAFE、なんて指定しないですよね… 何が起こってるんでしょうね?

投稿2016/10/29 09:56

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問