2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

itamae で読み取り権限のないファイルの編集

2
Posted at

itamae で下記のように書いた時、対象のファイルの読み取り権限がないと失敗する。

file "/path/to/file" do
  action :edit
  block do |s|
    # ...
  end
end

内部では net-scp を使ってファイルを取得 → 変更してアップロードしているので、ファイル取得時に読み取り権限がないと失敗する。

net-scp にモンキーパッチをあてて、sudo を使うようにすればよい。

require "net/scp"

module Net
  class SCP
    module Sudo
      def scp_command(*args)
        command = super
        "sudo " + command
      end
    end
  end
end

Net::SCP.prepend Net::SCP::Sudo

下記のテンプレートでは lib/sudo_scp.rb にこのコードを保存し、roles/* から require している。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?