Skip to content

Instantly share code, notes, and snippets.

@allaire
Last active March 28, 2018 21:53
Show Gist options
  • Save allaire/8419898 to your computer and use it in GitHub Desktop.
Save allaire/8419898 to your computer and use it in GitHub Desktop.
Capistrano 3 upload file from erb template
def template(from, to, options = {})
template_path = File.expand_path("../../templates/#{from}", __FILE__)
template = ERB.new(File.new(template_path).read).result(binding)
upload! StringIO.new(template), to, mode: 0644 # Otherwise it's set to 0640, which is not readable by other users (https://github.com/net-ssh/net-scp/blob/master/lib/net/scp/upload.rb#L63)
sudo "chown root:root #{to}" if options[:as_root]
end
@IwateKyle
Copy link

Does the upload! method include the 'sudo' prefix in the function call?

@allaire
Copy link
Author

allaire commented Dec 7, 2017

@IwateKyle Nope, you have to edit sudoers file, see https://github.com/capistrano/sshkit/blob/158c2867071e015a117e188d1a0ee7b579c9b24e/lib/sshkit/backends/netssh.rb

@uribefache I was missing a ../, I just fixed it :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment