aell 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/aell.gemspec +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/aell +117 -0
- data/lib/aell.rb +6 -0
- data/lib/aell/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c21d73c186534e4f439d42d762ffe4cf97ac7590981fea017de02e384d5d9dc9
|
4
|
+
data.tar.gz: 6145658d3ef742ad3989e61b9d69ed1643f94a51eeea36016c96cd9c0e635810
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87fb47f0f0084fb13ede06a4acb00111d2531c5950f34f58d4bdaa27bb3f057fbbe1cb0fab60c17d67ca460e6ed5e3dc641b5eea1281bb3fb7c20fb41e86d8f0
|
7
|
+
data.tar.gz: 254553736aaa335d3d1dfa897e0eaa8fe51e0d011feb130009e4c719809e916e63f60483032a135ef2e517168be6d005e0d7cbc32f5ab54c557c21dd9d2cb03b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aell (0.1.0)
|
5
|
+
aws-sdk-ec2 (~> 1.137)
|
6
|
+
net-ssh-multi (~> 1.2.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-eventstream (1.0.3)
|
12
|
+
aws-partitions (1.267.0)
|
13
|
+
aws-sdk-core (3.89.1)
|
14
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
15
|
+
aws-partitions (~> 1, >= 1.239.0)
|
16
|
+
aws-sigv4 (~> 1.1)
|
17
|
+
jmespath (~> 1.0)
|
18
|
+
aws-sdk-ec2 (1.137.0)
|
19
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
20
|
+
aws-sigv4 (~> 1.1)
|
21
|
+
aws-sigv4 (1.1.0)
|
22
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
23
|
+
coderay (1.1.2)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
jmespath (1.4.0)
|
26
|
+
method_source (0.9.2)
|
27
|
+
net-ssh (5.2.0)
|
28
|
+
net-ssh-gateway (2.0.0)
|
29
|
+
net-ssh (>= 4.0.0)
|
30
|
+
net-ssh-multi (1.2.1)
|
31
|
+
net-ssh (>= 2.6.5)
|
32
|
+
net-ssh-gateway (>= 1.2.0)
|
33
|
+
pry (0.12.2)
|
34
|
+
coderay (~> 1.1.0)
|
35
|
+
method_source (~> 0.9.0)
|
36
|
+
rake (10.5.0)
|
37
|
+
rspec (3.9.0)
|
38
|
+
rspec-core (~> 3.9.0)
|
39
|
+
rspec-expectations (~> 3.9.0)
|
40
|
+
rspec-mocks (~> 3.9.0)
|
41
|
+
rspec-core (3.9.1)
|
42
|
+
rspec-support (~> 3.9.1)
|
43
|
+
rspec-expectations (3.9.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.9.0)
|
46
|
+
rspec-mocks (3.9.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.9.0)
|
49
|
+
rspec-support (3.9.2)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
aell!
|
56
|
+
bundler (~> 1.17)
|
57
|
+
pry
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Carlos Atkinson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
# Aell
|
3
|
+
|
4
|
+
Aell let's you run commands on multiple servers querying by your host tags in your AWS Infrastructure
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To run this script you must have a ruby installed in your machine.
|
10
|
+
|
11
|
+
After that, you can install from RubyGems
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install aell
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To start using aell you need a `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION`, after that you can set the keys as environment variables:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
export AWS_ACCESS_KEY_ID=my_access_key
|
23
|
+
export AWS_SECRET_ACCESS_KEY=secret_access_key
|
24
|
+
export AWS_REGION=aws_region(eg: us-east-1)
|
25
|
+
```
|
26
|
+
|
27
|
+
Or set with the aell options in each command:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
aell - Application:some-app -u deploy-user --access_key_id access_key_id --secret_access_key secret_access_key --region us-east-1 -c 'echo "Hello Aell"'
|
31
|
+
```
|
32
|
+
Aell use AWS tags to query the servers with the `-t`/ `--tag` flags, to know more just type `aell -h`
|
33
|
+
|
34
|
+
## TODO
|
35
|
+
|
36
|
+
1. Configure a Docker image
|
37
|
+
2. Separate concerns
|
38
|
+
3. Add specs
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/catks/aell
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/aell.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aell/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aell"
|
8
|
+
spec.version = Aell::VERSION
|
9
|
+
spec.authors = ["Carlos Atkinson"]
|
10
|
+
spec.email = ["carlos.atks@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Run commands on multiple servers in your AWS Infrastructure}
|
13
|
+
spec.homepage = "https://github.com/catks/agell"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "aws-sdk-ec2", "~> 1.137"
|
27
|
+
spec.add_dependency "net-ssh-multi", "~> 1.2.1"
|
28
|
+
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aell"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/aell
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'net/ssh/multi'
|
2
|
+
require 'optparse'
|
3
|
+
require 'aell/version'
|
4
|
+
require 'aws-sdk-ec2'
|
5
|
+
|
6
|
+
AWS_ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID']
|
7
|
+
AWS_SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY']
|
8
|
+
AWS_REGION = ENV['AWS_REGION']
|
9
|
+
|
10
|
+
def verify_options!(options)
|
11
|
+
u error('Error: Missing user "-u my_user"') unless options[:user]
|
12
|
+
error('Error: Missing tag "-t some_tag:example" or hosts "-h 10.0.0.1,my_domain.intra"') unless options[:tag] || options[:hosts]
|
13
|
+
error('Error: Missing command "-c some_command"') unless options[:command]
|
14
|
+
error('Error: Missing AWS_ACCESS_KEY_ID, set with AWS_ACCESS_KEY_ID environment variable or with "--access_key_id my_key"') unless options[:access_key_id] || options[:hosts]
|
15
|
+
error('Error: Missing AWS_SECRET_ACCESS_KEY, set with AWS_SECRET_ACCESS_KEY environment variable or with "--secret_access_key my_key"') unless options[:secret_access_key] || options[:hosts]
|
16
|
+
error('Error: Missing AWS_REGION, set with AWS_REGION environment variable or with "--region region"') unless options[:region] || options[:hosts]
|
17
|
+
end
|
18
|
+
|
19
|
+
def error(message)
|
20
|
+
$stderr.puts message
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_tags(tags)
|
25
|
+
tag, values = tags.split(':')
|
26
|
+
parsed_values = values.split(',')
|
27
|
+
|
28
|
+
[tag, parsed_values]
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_servers_ips(access_key_id, secret_access_key, region, tags)
|
32
|
+
tag, values = parse_tags(tags)
|
33
|
+
|
34
|
+
ec2_client = Aws::EC2::Client.new(access_key_id: access_key_id, secret_access_key: secret_access_key, region: region)
|
35
|
+
ec2 = Aws::EC2::Resource.new(client: ec2_client)
|
36
|
+
ec2.instances({
|
37
|
+
filters:
|
38
|
+
[{
|
39
|
+
name: "tag:#{tag}",
|
40
|
+
values: values
|
41
|
+
}]
|
42
|
+
})
|
43
|
+
.collect { |i| i.private_ip_address }
|
44
|
+
end
|
45
|
+
|
46
|
+
options = {
|
47
|
+
access_key_id: AWS_ACCESS_KEY_ID,
|
48
|
+
secret_access_key: AWS_SECRET_ACCESS_KEY,
|
49
|
+
region: AWS_REGION
|
50
|
+
}
|
51
|
+
|
52
|
+
OptionParser.new do |opts|
|
53
|
+
opts.banner = <<-BANNER
|
54
|
+
Aell - Run commands in multiple servers querying by your AWS Infrastructure
|
55
|
+
|
56
|
+
Usage: aell -t some_tag:some_value -u ssh_user -c some_command
|
57
|
+
|
58
|
+
BANNER
|
59
|
+
|
60
|
+
opts.on("-t", "--tag TAG",
|
61
|
+
"AWS tags to search servers(you can specify more than one value with `,`)") do |tag|
|
62
|
+
options[:tag] = tag
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on("--hosts 'some.domain,10.0.0.1'",
|
66
|
+
"specify the hosts to run the command(Separated by `,`)") do |hosts|
|
67
|
+
options[:hosts] = hosts.split(',')
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on("-c", "--command COMMAND", "Command to run in the servers") do |command|
|
71
|
+
options[:command] = command
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on("-u", "--user USER", "User to connect in the servers") do |user|
|
75
|
+
options[:user] = user
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on("-v", "--version", "Shows aell version") do
|
79
|
+
puts Aell::VERSION
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
|
83
|
+
opts.on("--access_key_id ACCESS_KEY_ID", "Sets the AWS ACCESS_KEY_ID") do |access_key_id|
|
84
|
+
options[:access_key_id] = access_key_id
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on("--secret_access_key SECRET_ACCESS_KEY", "Sets the AWS SECRET_ACCESS_KEY") do |secret_access_key|
|
88
|
+
options[:secret_access_key] = secret_access_key
|
89
|
+
end
|
90
|
+
|
91
|
+
opts.on("--region REGION", "Sets the REGION") do |region|
|
92
|
+
options[:region] = region
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
96
|
+
puts opts
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
end.parse!
|
100
|
+
|
101
|
+
verify_options!(options)
|
102
|
+
|
103
|
+
servers = options[:hosts] || get_servers_ips(options[:access_key_id], options[:secret_access_key], options[:region], options[:tag])
|
104
|
+
|
105
|
+
begin
|
106
|
+
Thread.report_on_exception = false
|
107
|
+
Net::SSH::Multi.start do |session|
|
108
|
+
servers.each do |server|
|
109
|
+
session.use(options[:user] ? "#{options[:user]}@#{server}" : server)
|
110
|
+
end
|
111
|
+
|
112
|
+
session.exec options[:command]
|
113
|
+
end
|
114
|
+
|
115
|
+
rescue Net::SSH::ConnectionTimeout => e
|
116
|
+
error("Error: Can't connect to hosts #{servers}")
|
117
|
+
end
|
data/lib/aell.rb
ADDED
data/lib/aell/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Atkinson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-ec2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.137'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.137'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-ssh-multi
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- carlos.atks@gmail.com
|
100
|
+
executables:
|
101
|
+
- aell
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- aell.gemspec
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/aell
|
117
|
+
- lib/aell.rb
|
118
|
+
- lib/aell/version.rb
|
119
|
+
homepage: https://github.com/catks/agell
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.0.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Run commands on multiple servers in your AWS Infrastructure
|
142
|
+
test_files: []
|