opswalrus 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +43 -0
- data/Gemfile.lock +1 -1
- data/LICENSE +277 -674
- data/README.md +16 -0
- data/lib/opswalrus/app.rb +12 -0
- data/lib/opswalrus/cli.rb +5 -0
- data/lib/opswalrus/host.rb +12 -5
- data/lib/opswalrus/ops_file_script.rb +6 -4
- data/lib/opswalrus/version.rb +1 -1
- data/lib/opswalrus/walrus_lang.rb +11 -2
- data/opswalrus.gemspec +17 -16
- metadata +32 -30
data/README.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
opswalrus is a tool that runs scripts against hosts. It's kind of like Ansible, but aims to be simpler to use.
|
4
4
|
|
5
|
+
# Getting started
|
6
|
+
|
7
|
+
You have two options:
|
8
|
+
- Install via Rubygems
|
9
|
+
- Install via Docker
|
10
|
+
|
11
|
+
## Rubygems install
|
12
|
+
|
13
|
+
## Docker install
|
14
|
+
|
15
|
+
```shell
|
16
|
+
alias ops='docker run --rm -it -v $HOME/.ssh:/root/.ssh -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}/:/workdir ghcr.io/opswalrus/ops'
|
17
|
+
|
18
|
+
ops --version
|
19
|
+
```
|
20
|
+
|
5
21
|
# Examples
|
6
22
|
|
7
23
|
```bash
|
data/lib/opswalrus/app.rb
CHANGED
@@ -64,6 +64,14 @@ module OpsWalrus
|
|
64
64
|
"" # return empty string because we won't want anyone accidentally printing or inspecting @sudo_password
|
65
65
|
end
|
66
66
|
|
67
|
+
def emit_json_output!
|
68
|
+
@emit_json_output = true
|
69
|
+
end
|
70
|
+
|
71
|
+
def emit_json_output?
|
72
|
+
@emit_json_output
|
73
|
+
end
|
74
|
+
|
67
75
|
def set_local_hostname(hostname)
|
68
76
|
hostname = hostname.strip
|
69
77
|
@local_hostname = hostname.empty? ? "localhost" : hostname
|
@@ -186,6 +194,10 @@ module OpsWalrus
|
|
186
194
|
puts JSON.pretty_generate(result.value)
|
187
195
|
end
|
188
196
|
|
197
|
+
if emit_json_output?
|
198
|
+
puts JSON.pretty_generate(result.value)
|
199
|
+
end
|
200
|
+
|
189
201
|
exit_status
|
190
202
|
ensure
|
191
203
|
FileUtils.remove_entry(tmp_dir) if tmp_dir
|
data/lib/opswalrus/cli.rb
CHANGED
@@ -53,6 +53,7 @@ module OpsWalrus
|
|
53
53
|
c.flag [:u, :user], desc: "Specify the user that the operation will run as"
|
54
54
|
c.switch :pass, desc: "Prompt for a sudo password"
|
55
55
|
c.flag [:p, :params], desc: "JSON string that represents the input parameters for the operation. The JSON string must conform to the params schema for the operation."
|
56
|
+
c.switch :json, desc: "Emit JSON output"
|
56
57
|
|
57
58
|
c.action do |global_options, options, args|
|
58
59
|
hosts = global_options[:hosts] || []
|
@@ -80,6 +81,10 @@ module OpsWalrus
|
|
80
81
|
$app.prompt_sudo_password
|
81
82
|
end
|
82
83
|
|
84
|
+
if options[:json]
|
85
|
+
$app.emit_json_output!
|
86
|
+
end
|
87
|
+
|
83
88
|
# puts "verbose"
|
84
89
|
# puts verbose.inspect
|
85
90
|
# puts "user"
|
data/lib/opswalrus/host.rb
CHANGED
@@ -86,19 +86,26 @@ module OpsWalrus
|
|
86
86
|
# so we want to build up a command and send it to the remote host via HostDSL#run_ops
|
87
87
|
@method_chain.unshift(Bundler::BUNDLE_DIR) if @is_invocation_a_call_to_package_in_bundle_dir
|
88
88
|
|
89
|
-
|
90
|
-
# remote_run_command_args << path_to_ops_file_basename
|
89
|
+
remote_run_command_args = "--json"
|
91
90
|
|
92
|
-
remote_run_command_args
|
91
|
+
remote_run_command_args << " "
|
92
|
+
remote_run_command_args << @method_chain.join(" ")
|
93
93
|
|
94
94
|
unless args.empty?
|
95
95
|
remote_run_command_args << " "
|
96
96
|
remote_run_command_args << args.join(" ")
|
97
97
|
end
|
98
98
|
|
99
|
-
unless
|
99
|
+
unless kwargs.empty?
|
100
100
|
remote_run_command_args << " "
|
101
|
-
remote_run_command_args <<
|
101
|
+
remote_run_command_args << kwargs.map do |k, v|
|
102
|
+
case v
|
103
|
+
when Array
|
104
|
+
v.map {|v_element| "#{k}:#{v_element}" }
|
105
|
+
else
|
106
|
+
"#{k}:#{v}"
|
107
|
+
end
|
108
|
+
end.join(" ")
|
102
109
|
end
|
103
110
|
|
104
111
|
@host_proxy.run_ops(:run, remote_run_command_args)
|
@@ -148,9 +148,11 @@ module OpsWalrus
|
|
148
148
|
# we run the block in the context of the host, s.t. `self` within the block evaluates to `host`
|
149
149
|
retval = host.instance_exec(local_host, &block) # host is passed as the argument to the block
|
150
150
|
|
151
|
+
puts retval.inspect
|
152
|
+
|
151
153
|
# cleanup
|
152
|
-
if
|
153
|
-
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip",
|
154
|
+
if tmp_bundle_root_dir =~ /tmp/ # sanity check the temp path before we blow away something we don't intend
|
155
|
+
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip", tmp_bundle_root_dir)
|
154
156
|
else
|
155
157
|
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip")
|
156
158
|
end
|
@@ -222,12 +224,12 @@ module OpsWalrus
|
|
222
224
|
@runtime_env.resolve_import_reference(@ops_file_script.ops_file, import_reference)
|
223
225
|
end
|
224
226
|
|
225
|
-
def params(*keys)
|
227
|
+
def params(*keys, default: nil)
|
226
228
|
keys = keys.map(&:to_s)
|
227
229
|
if keys.empty?
|
228
230
|
@params
|
229
231
|
else
|
230
|
-
@params.dig(*keys)
|
232
|
+
@params.dig(*keys) || default
|
231
233
|
end
|
232
234
|
end
|
233
235
|
|
data/lib/opswalrus/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "citrus"
|
2
|
+
require "ostruct"
|
2
3
|
require "stringio"
|
3
4
|
|
4
5
|
module WalrusLang
|
@@ -54,9 +55,17 @@ module WalrusLang
|
|
54
55
|
|
55
56
|
Citrus.eval(Grammar)
|
56
57
|
|
57
|
-
|
58
|
+
# binding_obj : Binding | Hash
|
59
|
+
def self.render(template, binding_obj)
|
60
|
+
binding_obj = binding_obj.to_binding if binding_obj.is_a?(Hash)
|
58
61
|
ast = WalrusLang::Parser.parse(template)
|
59
|
-
ast.render(
|
62
|
+
ast.render(binding_obj)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Hash
|
67
|
+
def to_binding
|
68
|
+
OpenStruct.new(self).instance_eval { binding }
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
data/opswalrus.gemspec
CHANGED
@@ -3,14 +3,15 @@
|
|
3
3
|
require_relative "lib/opswalrus/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
10
|
-
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
6
|
+
spec.name = "opswalrus"
|
7
|
+
spec.version = OpsWalrus::VERSION
|
8
|
+
spec.authors = ["David Ellis"]
|
9
|
+
spec.email = ["david@conquerthelawn.com"]
|
10
|
+
|
11
|
+
spec.summary = "opswalrus is a tool that runs scripts against a fleet of hosts"
|
12
|
+
spec.description = "opswalrus is a tool that runs scripts against a fleet of hosts hosts. It's kind of like Ansible, but aims to be simpler to use."
|
13
|
+
spec.homepage = "https://github.com/opswalrus/opswalrus"
|
14
|
+
spec.license = 'EPL-2.0'
|
14
15
|
spec.required_ruby_version = ">= 2.6.0"
|
15
16
|
|
16
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
@@ -31,14 +32,14 @@ Gem::Specification.new do |spec|
|
|
31
32
|
spec.require_paths = ["lib"]
|
32
33
|
|
33
34
|
# gem dependencies
|
34
|
-
spec.add_dependency "citrus"
|
35
|
-
spec.add_dependency "gli"
|
36
|
-
spec.add_dependency "git"
|
37
|
-
spec.add_dependency "rubyzip"
|
38
|
-
|
39
|
-
spec.add_dependency "bcrypt_pbkdf"
|
40
|
-
spec.add_dependency "ed25519"
|
41
|
-
spec.add_dependency "sshkit"
|
35
|
+
spec.add_dependency "citrus", "~> 3.0"
|
36
|
+
spec.add_dependency "gli", '~> 2.21'
|
37
|
+
spec.add_dependency "git", '~> 1.18'
|
38
|
+
spec.add_dependency "rubyzip", '~> 2.3'
|
39
|
+
|
40
|
+
spec.add_dependency "bcrypt_pbkdf", '~> 1.1'
|
41
|
+
spec.add_dependency "ed25519", '~> 1.3'
|
42
|
+
spec.add_dependency "sshkit", '~> 1.21'
|
42
43
|
|
43
44
|
# For more information and examples about making a new gem, check out our
|
44
45
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opswalrus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Ellis
|
@@ -14,100 +14,100 @@ dependencies:
|
|
14
14
|
name: citrus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: gli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.21'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.21'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: git
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.18'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.18'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubyzip
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.3'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bcrypt_pbkdf
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.1'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: ed25519
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.3'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: sshkit
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.21'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.21'
|
111
111
|
description: opswalrus is a tool that runs scripts against a fleet of hosts hosts.
|
112
112
|
It's kind of like Ansible, but aims to be simpler to use.
|
113
113
|
email:
|
@@ -118,6 +118,7 @@ extensions: []
|
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
120
|
- ".rspec"
|
121
|
+
- Dockerfile
|
121
122
|
- Gemfile
|
122
123
|
- Gemfile.lock
|
123
124
|
- LICENSE
|
@@ -150,7 +151,8 @@ files:
|
|
150
151
|
- opswalrus.gemspec
|
151
152
|
- sig/opswalrus.rbs
|
152
153
|
homepage: https://github.com/opswalrus/opswalrus
|
153
|
-
licenses:
|
154
|
+
licenses:
|
155
|
+
- EPL-2.0
|
154
156
|
metadata:
|
155
157
|
homepage_uri: https://github.com/opswalrus/opswalrus
|
156
158
|
source_code_uri: https://github.com/opswalrus/opswalrus
|