vagrant-keymanager 1.0.6
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/.gitignore +36 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +22 -0
- data/README.md +59 -0
- data/Rakefile +13 -0
- data/lib/vagrant-keymanager/action/get_guest_keys.rb +36 -0
- data/lib/vagrant-keymanager/action.rb +16 -0
- data/lib/vagrant-keymanager/command.rb +33 -0
- data/lib/vagrant-keymanager/config.rb +58 -0
- data/lib/vagrant-keymanager/errors.rb +6 -0
- data/lib/vagrant-keymanager/hosts_file.rb +104 -0
- data/lib/vagrant-keymanager/plugin.rb +35 -0
- data/lib/vagrant-keymanager/provisioner.rb +25 -0
- data/lib/vagrant-keymanager/version.rb +5 -0
- data/lib/vagrant-keymanager.rb +14 -0
- data/locales/en.yml +8 -0
- data/test/Vagrantfile +35 -0
- data/test/test.sh +15 -0
- data/vagrant-keymanager.gemspec +22 -0
- data/vendor/cache/latest_specs.4.8 +0 -0
- data/vendor/cache/latest_specs.4.8.gz +0 -0
- data/vendor/cache/prerelease_specs.4.8 +0 -0
- data/vendor/cache/prerelease_specs.4.8.gz +0 -0
- data/vendor/cache/specs.4.8 +0 -0
- data/vendor/cache/specs.4.8.gz +0 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e10be7d86cef39986c9c2eec8ad99ee5fb70a79d
|
4
|
+
data.tar.gz: 840ec20d30f5de57f82a60b89e96c66c21b3ea84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 915d8801a877c8a8da00b1f29be02a54785943d7859e509b287c36b5a1a24acfadef10a27a5b093af54b9cd96e2b91f51021fd55325e4e852b3070826bff45d9
|
7
|
+
data.tar.gz: 5f569ed4ab3004be13d5eb37a65c0067c169e7e02ed874fd64a7840ee8b9257851fcebed76dc8b842e54d8b9952968cc01415d301f8fc9e7eecca4cb13444563
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
deploy.sh
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalisation:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.6
|
4
|
+
### Fixes
|
5
|
+
* Single-liner for get_user_key e get_root_key functions
|
6
|
+
|
7
|
+
|
8
|
+
## 1.0.5
|
9
|
+
### Fixes
|
10
|
+
* Changed logic in test file existence
|
11
|
+
|
12
|
+
|
13
|
+
## 1.0.4
|
14
|
+
### Fixes
|
15
|
+
* Changed logic in test file existence
|
16
|
+
|
17
|
+
|
18
|
+
## 1.0.3
|
19
|
+
### Fixes
|
20
|
+
* Removed wrong action hook "update_all" called during vagrant up
|
21
|
+
|
22
|
+
## 1.0.2
|
23
|
+
### Fixes
|
24
|
+
* Changed DOC
|
25
|
+
|
26
|
+
|
27
|
+
## 1.0.1
|
28
|
+
### Fixes
|
29
|
+
* Changed DOC
|
30
|
+
|
31
|
+
|
32
|
+
## 1.0.0
|
33
|
+
### Features
|
34
|
+
* supports vagrant 1.5
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/mitchellh/vagrant.git
|
3
|
+
revision: 6977e93ba98fd19112b1fed74dafb8619f581984
|
4
|
+
tag: v1.5.1
|
5
|
+
specs:
|
6
|
+
vagrant (1.5.1)
|
7
|
+
bundler (~> 1.5.2)
|
8
|
+
childprocess (~> 0.5.0)
|
9
|
+
erubis (~> 2.7.0)
|
10
|
+
i18n (~> 0.6.0)
|
11
|
+
listen (~> 2.4.0)
|
12
|
+
log4r (~> 1.1.9, < 1.1.11)
|
13
|
+
net-scp (~> 1.1.0)
|
14
|
+
net-ssh (>= 2.6.6, < 2.8.0)
|
15
|
+
rb-kqueue (~> 0.2.0)
|
16
|
+
wdm (~> 0.1.0)
|
17
|
+
|
18
|
+
PATH
|
19
|
+
remote: .
|
20
|
+
specs:
|
21
|
+
vagrant-keymanager (1.0.6)
|
22
|
+
|
23
|
+
GEM
|
24
|
+
remote: https://rubygems.org/
|
25
|
+
specs:
|
26
|
+
celluloid (0.16.0)
|
27
|
+
timers (~> 4.0.0)
|
28
|
+
childprocess (0.5.0)
|
29
|
+
ffi (~> 1.0, >= 1.0.11)
|
30
|
+
erubis (2.7.0)
|
31
|
+
ffi (1.9.8-x86-mingw32)
|
32
|
+
hitimes (1.2.2-x86-mingw32)
|
33
|
+
i18n (0.6.0)
|
34
|
+
listen (2.4.0)
|
35
|
+
celluloid (>= 0.15.2)
|
36
|
+
rb-fsevent (>= 0.9.3)
|
37
|
+
rb-inotify (>= 0.9)
|
38
|
+
log4r (1.1.9)
|
39
|
+
net-scp (1.1.0)
|
40
|
+
net-ssh (>= 2.6.5)
|
41
|
+
net-ssh (2.6.6)
|
42
|
+
rake (10.4.2)
|
43
|
+
rb-fsevent (0.9.4)
|
44
|
+
rb-inotify (0.9.5)
|
45
|
+
ffi (>= 0.5.0)
|
46
|
+
rb-kqueue (0.2.0)
|
47
|
+
ffi (>= 0.5.0)
|
48
|
+
timers (4.0.1)
|
49
|
+
hitimes
|
50
|
+
wdm (0.1.0)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
x86-mingw32
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.3)
|
57
|
+
rake
|
58
|
+
vagrant!
|
59
|
+
vagrant-keymanager!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Moviri
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Vagrant Key Manager
|
2
|
+
====================
|
3
|
+
`vagrant-keymanager` is a Vagrant 1.1+ plugin that sets SSH keys
|
4
|
+
on linux guest machines. It creates public+private keys on every
|
5
|
+
machine listed in your Vegrantfile and spreads the public keys
|
6
|
+
across all these machines. All machines should be already up and
|
7
|
+
running before provisioning or an error will occur.
|
8
|
+
Do not use with Windows guest machines.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
Install the plugin following the typical Vagrant 1.1 procedure:
|
13
|
+
|
14
|
+
$ vagrant plugin install vagrant-keymanager
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
|
19
|
+
You can use keymanager as a provisioner.
|
20
|
+
|
21
|
+
Use:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
config.vm.provision :keymanager
|
25
|
+
```
|
26
|
+
|
27
|
+
Let's assume you have three machines defined in you vagrant file.
|
28
|
+
This pluging will:
|
29
|
+
* connect to machine A
|
30
|
+
* generate private and public key for machine A (standard user and root user)
|
31
|
+
* grab public keys (standard and root) for machine A ad copy them to machine B and C
|
32
|
+
* Reperat the 3 steps above for machines B and C
|
33
|
+
|
34
|
+
There may be cases in which you want to perform some extra steps.
|
35
|
+
If that's the case you can code extra operations and pass with the optional parameter
|
36
|
+
extra_steps. Here's a basic example that counts all rsa ssh keys from your machines.
|
37
|
+
Just put the variable definition before the call to keymanager provisioner.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
node_config.vm.provider 'aws' do |aws, override|
|
41
|
+
aws.access_key_id = AWS_ACCESS_KEY
|
42
|
+
aws.secret_access_key = AWS_SECRET_KEY
|
43
|
+
aws.keypair_name = AWS_KPAIR_NAME
|
44
|
+
|
45
|
+
override.ssh.username = 'centos'
|
46
|
+
|
47
|
+
override.keymanager.extra_steps = proc do |curr_machine|
|
48
|
+
result = ""
|
49
|
+
curr_machine.communicate.execute("grep '^ssh-rsa' ~/.ssh/authorized_keys | wc -l") do |type, data|
|
50
|
+
result << data if type == :stdout
|
51
|
+
puts "Current machine has "+result+" SSH keys"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_helper'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
# Change to the directory of this file.
|
5
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
sh 'bash test/test.sh'
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'vagrant-keymanager/hosts_file'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module KeyManager
|
5
|
+
module Action
|
6
|
+
class GetGuestKeys
|
7
|
+
include HostsFile
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@global_env = @machine.env
|
13
|
+
@provider = env[:provider]
|
14
|
+
|
15
|
+
# config_global is deprecated from v1.5
|
16
|
+
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
|
17
|
+
@config = @global_env.vagrantfile.config
|
18
|
+
else
|
19
|
+
@config = @global_env.config_global
|
20
|
+
end
|
21
|
+
|
22
|
+
@logger = Log4r::Logger.new('vagrant::keymanager::get_guest_keys')
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
env[:ui].info I18n.t('vagrant_keymanager.action.get_guest_keys', {
|
27
|
+
:name => @machine.name
|
28
|
+
})
|
29
|
+
get_guest_keys(@machine)
|
30
|
+
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'vagrant-keymanager/action/get_guest_keys'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module KeyManager
|
5
|
+
module Action
|
6
|
+
include Vagrant::Action::Builtin
|
7
|
+
|
8
|
+
def self.get_guest_keys
|
9
|
+
Vagrant::Action::Builder.new.tap do |builder|
|
10
|
+
builder.use ConfigValidate
|
11
|
+
builder.use GeyGuestKeys
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module KeyManager
|
3
|
+
class Command < Vagrant.plugin('2', :command)
|
4
|
+
include HostsFile
|
5
|
+
|
6
|
+
def execute
|
7
|
+
options = {}
|
8
|
+
opts = OptionParser.new do |o|
|
9
|
+
o.banner = 'Usage: vagrant keymanager [vm-name]'
|
10
|
+
o.separator ''
|
11
|
+
o.version = VagrantPlugins::KeyManager::VERSION
|
12
|
+
o.program_name = 'vagrant keymanager'
|
13
|
+
|
14
|
+
o.on('--provider provider', String,
|
15
|
+
'Update machines with the specific provider.') do |provider|
|
16
|
+
options[:provider] = provider.to_sym
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
argv = parse_options(opts)
|
21
|
+
options[:provider] ||= @env.default_provider
|
22
|
+
|
23
|
+
# run keymanager for specified guest machines
|
24
|
+
with_target_vms(argv, options) do |machine|
|
25
|
+
@env.action_runner.run(Action.get_guest_keys, {
|
26
|
+
:machine => machine,
|
27
|
+
:provider => options[:provider]
|
28
|
+
})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module KeyManager
|
3
|
+
class Config < Vagrant.plugin('2', :config)
|
4
|
+
attr_accessor :extra_params
|
5
|
+
attr_accessor :extra_steps
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@extra_params = []
|
9
|
+
@extra_params = Array.new
|
10
|
+
@extra_steps = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def finalize!
|
14
|
+
@extra_params = [ @extra_params ].flatten
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate(machine)
|
18
|
+
errors = []
|
19
|
+
# errors << validate_bool('keymanager.enabled', @enabled)
|
20
|
+
errors.compact!
|
21
|
+
|
22
|
+
# check if extra_params option is an Array
|
23
|
+
if !machine.config.keymanager.extra_params.kind_of?(Array) &&
|
24
|
+
!machine.config.keymanager.extra_params.kind_of?(String)
|
25
|
+
errors << I18n.t('vagrant_keymanager.config.not_an_array_or_string', {
|
26
|
+
:config_key => 'keymanager.extra_params',
|
27
|
+
:is_class => extra_params.class.to_s,
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
if !machine.config.keymanager.extra_steps.nil? &&
|
32
|
+
!machine.config.keymanager.extra_steps.kind_of?(Proc)
|
33
|
+
errors << I18n.t('vagrant_keymanager.config.not_a_proc', {
|
34
|
+
:config_key => 'keymanager.extra_steps',
|
35
|
+
:is_class => extra_steps.class.to_s,
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
errors.compact!
|
40
|
+
{ "KeyManager configuration" => errors }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def validate_bool(key, value)
|
46
|
+
if ![TrueClass, FalseClass].include?(value.class) &&
|
47
|
+
value != UNSET_VALUE
|
48
|
+
I18n.t('vagrant_keymanager.config.not_a_bool', {
|
49
|
+
:config_key => key,
|
50
|
+
:value => value.class.to_s
|
51
|
+
})
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module KeyManager
|
6
|
+
module HostsFile
|
7
|
+
def get_guest_keys(machine)
|
8
|
+
machines = get_machines
|
9
|
+
|
10
|
+
sshkeys = Hash.new
|
11
|
+
sshrootkeys = Hash.new
|
12
|
+
|
13
|
+
#puts "MACHINES"
|
14
|
+
#pp machines
|
15
|
+
machines.each do |curr_machine|
|
16
|
+
#pp curr_machine
|
17
|
+
curr_machine_name=curr_machine.name.to_s
|
18
|
+
puts "Getting SSH keys from "+curr_machine_name
|
19
|
+
sshkey=get_user_key(curr_machine)
|
20
|
+
#puts "SSH key: "+sshkey
|
21
|
+
sshkeys[curr_machine_name] = sshkey
|
22
|
+
sshrootkey=get_root_key(curr_machine)
|
23
|
+
#puts "SSH root key: "+sshrootkey
|
24
|
+
sshrootkeys[curr_machine_name] = sshrootkey
|
25
|
+
end
|
26
|
+
|
27
|
+
machines.each do |curr_machine|
|
28
|
+
curr_machine_name=curr_machine.name.to_s
|
29
|
+
curr_machine.communicate.sudo("rm -f /tmp/.all_keys.txt /tmp/.all_root_keys.txt /tmp/add_ssh_keys.sh")
|
30
|
+
|
31
|
+
puts "Saving public SSH keys to "+curr_machine_name
|
32
|
+
ssh_keys_to_save=sshkeys.reject{|k,v| k == curr_machine_name}.values.join.gsub("\n\n", '\n')
|
33
|
+
curr_machine.communicate.execute("echo '"+ssh_keys_to_save+"' >/tmp/.all_keys.txt")
|
34
|
+
#puts "Saved /tmp/.all_keys.txt"
|
35
|
+
|
36
|
+
ssh_root_keys_to_save=sshrootkeys.reject{|k,v| k == curr_machine_name}.values.join.gsub("\n\n", '\n')
|
37
|
+
curr_machine.communicate.execute("echo '"+ssh_root_keys_to_save+"' >/tmp/.all_root_keys.txt")
|
38
|
+
|
39
|
+
#puts "Saved /tmp/.all_root_keys.txt"
|
40
|
+
|
41
|
+
# We must save locally a bash script that computes and applies diff and always exits with 0 or vagrant plugin will exit with an error
|
42
|
+
curr_machine.communicate.execute("echo 'diff --changed-group-format=\"%>\" --unchanged-group-format=\"\" ~/.ssh/authorized_keys $1 >>~/.ssh/authorized_keys;exit 0' >/tmp/add_ssh_keys.sh")
|
43
|
+
|
44
|
+
curr_machine.communicate.execute("sh /tmp/add_ssh_keys.sh /tmp/.all_keys.txt")
|
45
|
+
curr_machine.communicate.execute("sh /tmp/add_ssh_keys.sh /tmp/.all_root_keys.txt")
|
46
|
+
#puts "Saved user keys"
|
47
|
+
|
48
|
+
curr_machine.communicate.sudo("sh /tmp/add_ssh_keys.sh /tmp/.all_keys.txt")
|
49
|
+
curr_machine.communicate.sudo("sh /tmp/add_ssh_keys.sh /tmp/.all_root_keys.txt")
|
50
|
+
#puts "Saved root keys"
|
51
|
+
end
|
52
|
+
|
53
|
+
machines.each do |curr_machine|
|
54
|
+
call_extra_user_steps(curr_machine)
|
55
|
+
end
|
56
|
+
|
57
|
+
machines.each do |curr_machine|
|
58
|
+
curr_machine.communicate.sudo("rm -f /tmp/.all_keys.txt /tmp/.all_root_keys.txt /tmp/add_ssh_keys.sh")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def get_user_key(machine)
|
65
|
+
sshresult=""
|
66
|
+
machine.communicate.execute("if [ ! -e ~/.ssh/id_rsa ] || [ ! -e ~/.ssh/id_rsa.pub ]; then ssh-keygen -q -f ~/.ssh/id_rsa -P ''; fi; cat ~/.ssh/id_rsa.pub") do |type, data|
|
67
|
+
sshresult << data if type == :stdout
|
68
|
+
end
|
69
|
+
return sshresult
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_root_key(machine)
|
73
|
+
sshrootresult = ""
|
74
|
+
machine.communicate.sudo("if [ ! -e ~/.ssh/id_rsa ] || [ ! -e ~/.ssh/id_rsa.pub ]; then ssh-keygen -q -f ~/.ssh/id_rsa -P ''; fi; cat ~/.ssh/id_rsa.pub") do |type, data|
|
75
|
+
sshrootresult << data if type == :stdout
|
76
|
+
end
|
77
|
+
return sshrootresult
|
78
|
+
end
|
79
|
+
|
80
|
+
def call_extra_user_steps(resolving_machine)
|
81
|
+
extra_user_steps = machine.config.keymanager.extra_steps
|
82
|
+
if extra_user_steps
|
83
|
+
machines = @global_env.machine_names
|
84
|
+
machines.map { |machine| extra_user_steps.call(machine, resolving_machine) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_machines
|
89
|
+
machines = @global_env.machine_names
|
90
|
+
# Collect only machines that exist for the current provider
|
91
|
+
machines.collect do |name|
|
92
|
+
begin
|
93
|
+
machine = @global_env.machine(name, @provider)
|
94
|
+
rescue Vagrant::Errors::MachineNotFound
|
95
|
+
# ignore
|
96
|
+
end
|
97
|
+
machine
|
98
|
+
end
|
99
|
+
.reject(&:nil?)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'vagrant-keymanager/action'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module KeyManager
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
6
|
+
name 'KeyManager'
|
7
|
+
description <<-DESC
|
8
|
+
This plugin gets/sets SSH keys from/to guest machine.
|
9
|
+
|
10
|
+
You can also use the keymanager provisioner.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
config(:keymanager) do
|
14
|
+
require_relative 'config'
|
15
|
+
Config
|
16
|
+
end
|
17
|
+
|
18
|
+
provisioner(:keymanager) do
|
19
|
+
require_relative 'provisioner'
|
20
|
+
Provisioner
|
21
|
+
end
|
22
|
+
|
23
|
+
# Work-around for vagrant >= 1.5
|
24
|
+
# It breaks without a provisioner config, so we provide a dummy one
|
25
|
+
config(:keymanager, :provisioner) do
|
26
|
+
::Vagrant::Config::V2::DummyConfig.new
|
27
|
+
end
|
28
|
+
|
29
|
+
command(:keymanager) do
|
30
|
+
require_relative 'command'
|
31
|
+
Command
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module KeyManager
|
3
|
+
class Provisioner < Vagrant.plugin('2', :provisioner)
|
4
|
+
include HostsFile
|
5
|
+
|
6
|
+
def initialize(machine, config)
|
7
|
+
super(machine, config)
|
8
|
+
@global_env = machine.env
|
9
|
+
@provider = machine.provider_name
|
10
|
+
|
11
|
+
# config_global is deprecated from v1.5
|
12
|
+
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
|
13
|
+
@config = @global_env.vagrantfile.config
|
14
|
+
else
|
15
|
+
@config = @global_env.config_global
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def provision
|
21
|
+
get_guest_keys(@machine)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'vagrant-keymanager/plugin'
|
2
|
+
require 'vagrant-keymanager/version'
|
3
|
+
require 'vagrant-keymanager/errors'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module KeyManager
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
9
|
+
end
|
10
|
+
|
11
|
+
I18n.load_path << File.expand_path('locales/en.yml', source_root)
|
12
|
+
I18n.reload!
|
13
|
+
end
|
14
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_keymanager:
|
3
|
+
action:
|
4
|
+
get_guest_keys: "Getting SSH keys from [%{name}] ..."
|
5
|
+
config:
|
6
|
+
not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
|
7
|
+
not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{is_class}'"
|
8
|
+
not_a_proc: "A value for %{config_key} must be a Proc, not type '%{is_class}'"
|
data/test/Vagrantfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
if Gem::Version.new(::Vagrant::VERSION) < Gem::Version.new('1.5')
|
5
|
+
Vagrant.require_plugin('vagrant-keymanager')
|
6
|
+
end
|
7
|
+
|
8
|
+
Vagrant.configure('2') do |config|
|
9
|
+
|
10
|
+
if ENV.key? 'VAGRANT_BOX'
|
11
|
+
config.vm.box = ENV['VAGRANT_BOX']
|
12
|
+
else
|
13
|
+
config.vm.box = 'precise64'
|
14
|
+
config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-amd64-disk1.box'
|
15
|
+
end
|
16
|
+
|
17
|
+
config.keymanager.enabled = true
|
18
|
+
config.keymanager.manage_host = true
|
19
|
+
|
20
|
+
config.vm.define :server1 do |server|
|
21
|
+
server.vm.hostname = 'fry'
|
22
|
+
server.vm.network :private_network, :ip => '10.0.5.2'
|
23
|
+
end
|
24
|
+
|
25
|
+
config.vm.define :server2 do |server|
|
26
|
+
server.vm.hostname = 'bender'
|
27
|
+
server.vm.network :private_network, :ip => '10.0.5.3'
|
28
|
+
end
|
29
|
+
|
30
|
+
config.vm.define :server3 do |server|
|
31
|
+
server.vm.hostname = 'leena'
|
32
|
+
server.vm.network :private_network, :ip => '10.0.5.4'
|
33
|
+
server.vm.provision :keymanager
|
34
|
+
end
|
35
|
+
end
|
data/test/test.sh
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
cd test
|
2
|
+
|
3
|
+
vagrant up
|
4
|
+
|
5
|
+
vagrant keymanager
|
6
|
+
vagrant keymanager
|
7
|
+
|
8
|
+
echo "[server1] SSH keys:"
|
9
|
+
vagrant ssh server1 -c 'cat ~/.ssh/authorized_keys'
|
10
|
+
echo "[server2] SSH keys:"
|
11
|
+
vagrant ssh server2 -c 'cat ~/.ssh/authorized_keys'
|
12
|
+
|
13
|
+
vagrant destroy -f
|
14
|
+
|
15
|
+
cd ..
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'vagrant-keymanager/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = 'vagrant-keymanager'
|
9
|
+
gem.version = VagrantPlugins::KeyManager::VERSION
|
10
|
+
gem.authors = ['Giorgio Baldaccini']
|
11
|
+
gem.email = ['giorgio.baldaccini@moviri.com']
|
12
|
+
gem.description = %q{A Vagrant plugin that manages SSH keys within a multi-machine environment}
|
13
|
+
gem.summary = gem.description
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.3'
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-keymanager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giorgio Baldaccini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A Vagrant plugin that manages SSH keys within a multi-machine environment
|
42
|
+
email:
|
43
|
+
- giorgio.baldaccini@moviri.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- CHANGELOG.md
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/vagrant-keymanager.rb
|
56
|
+
- lib/vagrant-keymanager/action.rb
|
57
|
+
- lib/vagrant-keymanager/action/get_guest_keys.rb
|
58
|
+
- lib/vagrant-keymanager/command.rb
|
59
|
+
- lib/vagrant-keymanager/config.rb
|
60
|
+
- lib/vagrant-keymanager/errors.rb
|
61
|
+
- lib/vagrant-keymanager/hosts_file.rb
|
62
|
+
- lib/vagrant-keymanager/plugin.rb
|
63
|
+
- lib/vagrant-keymanager/provisioner.rb
|
64
|
+
- lib/vagrant-keymanager/version.rb
|
65
|
+
- locales/en.yml
|
66
|
+
- test/Vagrantfile
|
67
|
+
- test/test.sh
|
68
|
+
- vagrant-keymanager.gemspec
|
69
|
+
- vendor/cache/latest_specs.4.8
|
70
|
+
- vendor/cache/latest_specs.4.8.gz
|
71
|
+
- vendor/cache/prerelease_specs.4.8
|
72
|
+
- vendor/cache/prerelease_specs.4.8.gz
|
73
|
+
- vendor/cache/specs.4.8
|
74
|
+
- vendor/cache/specs.4.8.gz
|
75
|
+
homepage:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.6
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A Vagrant plugin that manages SSH keys within a multi-machine environment
|
99
|
+
test_files:
|
100
|
+
- test/Vagrantfile
|
101
|
+
- test/test.sh
|