kentaroi / sshkit-sudo Goto Github PK
View Code? Open in Web Editor NEWSSHKit extension, for sudo operation with password input. It can be used in Capistrano 3 tasks.
License: MIT License
SSHKit extension, for sudo operation with password input. It can be used in Capistrano 3 tasks.
License: MIT License
If you deploy to multiple servers that require typing in a password, all the prompts get concatenated together and you end up only being able to respond to one of them (this is true even if its the same password for each server). The code that requests passwords should be protected by a mutex so you can handle each server one at a time.
I was wondering if it might be possible to implement a capture_sudo
method?
I have monkey patched this as follows:
module SSHKit
module Backend
class Netssh < Printer
def capture_sudo(*args)
result = _execute!(:sudo, *args)
result.full_stdout.sub(%r{^\[sudo\] password for .*\r\n}, '')
end
end
end
end
This is quite an unpleasant implementation, but it seems to work. Is there a better way of supporting this?
Trying to use this with sshkit 1.8.1. It prompts for the sudo password but then immediately goes to new line.
I was wondering if it would be possible to support calls to the as() method?
For some reason I couldn't work out, when execute is called, it does not call the patched _execute! method, it calls the original one, which hangs waiting for input.
I couldn't understand the class hierarchy, but is something that could be fixed?
my task looks like this:
desc 'initialize certbot / letsencrypt for cloudflare'
task :init do
on roles(:app), in: :sequence do
execute! :sudo, :touch, '/etc/letsencrypt/cloudflare.ini'
execute! :sudo, :chmod, '600 /etc/letsencrypt/cloudflare.ini'
# also tried execute! :sudo, :printf,.....
sudo :printf, "'dns_cloudflare_email = [email protected]\ndns_cloudflare_api_key = #{fetch(:cloudflare_api_key)}' > /etc/letsencrypt/cloudflare.ini"
end
end
Creating files works, but as I try to write into it, it stops.
Also tried printf without touching first
But I always get this error:
04 sudo printf 'dns_cloudflare_email = [email protected]
dns_cloudflare_api_key = 123456789890…
04 bash: /etc/letsencrypt/cloudflare.ini: Permission denied
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: sudo exit status: 1
sudo stdout: bash: /etc/letsencrypt/cloudflare.ini: Permission denied
sudo stderr: Nothing written
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
SSHKit::Command::Failed: sudo exit status: 1
sudo stdout: bash: /etc/letsencrypt/cloudflare.ini: Permission denied
sudo stderr: Nothing written
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/command.rb:99:in `exit_status='
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/netssh.rb:50:in `execute_command!'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/abstract.rb:21:in `block in create_command_and_execute!'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/abstract.rb:21:in `tap'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/abstract.rb:21:in `create_command_and_execute!'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/abstract.rb:12:in `execute!'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-sudo-0.1.0/lib/sshkit/sudo/backends/abstract.rb:6:in `sudo'
config/deploy.rb:105:in `block (3 levels) in <top (required)>'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/backends/abstract.rb:29:in `run'
/Users/jan/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => letsencrypt:init
Did I miss something?
In my Gemfile
gem 'capistrano', '3.4.0'
gem 'sshkit-sudo', github: 'kentaroi/sshkit-sudo'
In Capfile
require 'sshkit/sudo'
bundle exec cap -T results in
TypeError: superclass mismatch for class Netssh in require
I'd encountered this error and resolved require 'io/console'
.
Do this gem need io/console
?
I suppose It should be wrotten in README.
Or is it a common knowledge in ruby?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.