From 3d0c0e873c8df53f82ce9f71090028d7a8e53990 Mon Sep 17 00:00:00 2001 From: Gosuke Miyashita Date: Wed, 8 Nov 2017 01:39:43 +0900 Subject: [PATCH] Add Ruby examples using SSH backend --- .../{ssh_backend.rb => ssh_backend_with_agent.rb} | 2 +- ruby/ssh_backend_with_key_file.rb | 15 +++++++++++++++ ruby/ssh_backend_with_password.rb | 15 +++++++++++++++ ruby/ssh_backend_with_port.rb | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) rename ruby/{ssh_backend.rb => ssh_backend_with_agent.rb} (69%) create mode 100644 ruby/ssh_backend_with_key_file.rb create mode 100644 ruby/ssh_backend_with_password.rb create mode 100644 ruby/ssh_backend_with_port.rb diff --git a/ruby/ssh_backend.rb b/ruby/ssh_backend_with_agent.rb similarity index 69% rename from ruby/ssh_backend.rb rename to ruby/ssh_backend_with_agent.rb index e476766..c00c9bc 100644 --- a/ruby/ssh_backend.rb +++ b/ruby/ssh_backend_with_agent.rb @@ -1,7 +1,7 @@ require 'libspecinfra' require 'libspecinfra/backend/ssh' -b = Libspecinfra::Backend::SSH::Binding.new("localhost") +b = Libspecinfra::Backend::SSH::Binding.new("localhost", "mizzy") s = Libspecinfra::Specinfra::Binding.new(b) f = s.file("/etc/passwd") diff --git a/ruby/ssh_backend_with_key_file.rb b/ruby/ssh_backend_with_key_file.rb new file mode 100644 index 0000000..7927f87 --- /dev/null +++ b/ruby/ssh_backend_with_key_file.rb @@ -0,0 +1,15 @@ +require 'libspecinfra' +require 'libspecinfra/backend/ssh' + +b = Libspecinfra::Backend::SSH::Binding.new( + "localhost", + "mizzy", + { + key_file: "/Users/mizzy/.ssh/id_rsa", + }, +) + +s = Libspecinfra::Specinfra::Binding.new(b) +f = s.file("/etc/passwd") + +printf("%#o", f.mode) diff --git a/ruby/ssh_backend_with_password.rb b/ruby/ssh_backend_with_password.rb new file mode 100644 index 0000000..9e6cb3d --- /dev/null +++ b/ruby/ssh_backend_with_password.rb @@ -0,0 +1,15 @@ +require 'libspecinfra' +require 'libspecinfra/backend/ssh' + +b = Libspecinfra::Backend::SSH::Binding.new( + "localhost", + "mizzy", + { + password: "******", + }, +) + +s = Libspecinfra::Specinfra::Binding.new(b) +f = s.file("/etc/passwd") + +printf("%#o", f.mode) diff --git a/ruby/ssh_backend_with_port.rb b/ruby/ssh_backend_with_port.rb new file mode 100644 index 0000000..51d952b --- /dev/null +++ b/ruby/ssh_backend_with_port.rb @@ -0,0 +1,15 @@ +require 'libspecinfra' +require 'libspecinfra/backend/ssh' + +b = Libspecinfra::Backend::SSH::Binding.new( + "localhost", + "mizzy", + { + port: 22, + }, +) + +s = Libspecinfra::Specinfra::Binding.new(b) +f = s.file("/etc/passwd") + +printf("%#o", f.mode)