vagrant-execute 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/vagrant-execute.rb +79 -0
- data/lib/vagrant-execute/version.rb +5 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d22a45518eaffdece6e86b712d26c00fac9eb072
|
4
|
+
data.tar.gz: 2e39ec11f406ad908a39ed7c45385409e5187e32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e335f450ac9658db8ce396179aaf06c7f7170657c64520829caebe4b23abbfc4fe8c7a922728427dbf63c16fba60d709044808b3f6d84438c923625d96b2679b
|
7
|
+
data.tar.gz: a509557e47306429b28c2b64c86f294ecc509b1ddc1d69de7eb1e0a6a21823da505b0d929b3fc8d9b762ef2e81e5fe915fdf9142dd8b0f8a97830294f056d08b
|
@@ -0,0 +1,79 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant Execute plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
if Vagrant::VERSION < "1.9.0"
|
8
|
+
raise "The Vagrant Execute plugin is only compatible with Vagrant 1.9+"
|
9
|
+
end
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module Execute
|
13
|
+
class Plugin < Vagrant.plugin("2")
|
14
|
+
name "execute"
|
15
|
+
description "Vagrant plugin to execute commands inside a VM from the host machine."
|
16
|
+
|
17
|
+
command "execute" do
|
18
|
+
class Command < Vagrant.plugin("2", :command)
|
19
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/machine.rb
|
20
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/plugin/v2/communicator.rb
|
21
|
+
def execute
|
22
|
+
options = {}
|
23
|
+
options[:sudo] = false
|
24
|
+
options[:command] = ""
|
25
|
+
|
26
|
+
opts = OptionParser.new do |o|
|
27
|
+
o.banner = "Usage: vagrant execute [vm-name] -c command"
|
28
|
+
o.separator ""
|
29
|
+
o.on("--sudo", "Execute with sudo") do |v|
|
30
|
+
options[:sudo] = v
|
31
|
+
end
|
32
|
+
o.on("-c", "--command COMMAND", "Command to execute") do |v|
|
33
|
+
options[:command] = v
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
vms = parse_options(opts)
|
38
|
+
|
39
|
+
with_target_vms(vms) do |machine|
|
40
|
+
if options[:sudo]
|
41
|
+
machine.communicate.sudo(options[:command], {elevated: true, interactive: false}) do |type, data|
|
42
|
+
handle_comm(machine, type, data)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
machine.communicate.execute(options[:command]) do |type, data|
|
46
|
+
handle_comm(machine, type, data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def cleanup
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
# This handles outputting the communication data back to the UI
|
58
|
+
def handle_comm(machine, type, data)
|
59
|
+
if [:stderr, :stdout].include?(type)
|
60
|
+
# Output the data with the proper color based on the stream.
|
61
|
+
color = type == :stdout ? :green : :red
|
62
|
+
|
63
|
+
# Clear out the newline since we add one
|
64
|
+
data = data.chomp
|
65
|
+
return if data.empty?
|
66
|
+
|
67
|
+
options = {}
|
68
|
+
options[:color] = color #if !config.keep_color
|
69
|
+
|
70
|
+
machine.ui.info(data.chomp, options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Command
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-execute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rui Lopes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Vagrant plugin for executing commands.
|
28
|
+
email: rgl@ruilopes.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/vagrant-execute.rb
|
34
|
+
- lib/vagrant-execute/version.rb
|
35
|
+
homepage: https://github.com/rgl/vagrant-execute
|
36
|
+
licenses:
|
37
|
+
- LGPLv3
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Vagrant plugin for executing commands.
|
59
|
+
test_files: []
|