vagrant-ansible_auto 0.1.5 → 0.2.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 +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +172 -0
- data/README.md +53 -12
- data/Rakefile +9 -7
- data/TODO.md +14 -0
- data/Vagrantfile +37 -15
- data/lib/vagrant/ansible_auto/cap/guest/posix/check_open_port.rb +22 -3
- data/lib/vagrant/ansible_auto/cap/guest/posix/executable_installed.rb +10 -2
- data/lib/vagrant/ansible_auto/cap/guest/posix/gateway_addresses.rb +8 -23
- data/lib/vagrant/ansible_auto/cap/guest/posix/private_key.rb +16 -1
- data/lib/vagrant/ansible_auto/cap/guest/posix/public_key.rb +18 -3
- data/lib/vagrant/ansible_auto/cap/guest/posix/ssh_server_address.rb +22 -12
- data/lib/vagrant/ansible_auto/cap/guest/posix.rb +16 -0
- data/lib/vagrant/ansible_auto/command/inventory.rb +37 -11
- data/lib/vagrant/ansible_auto/command/root.rb +34 -31
- data/lib/vagrant/ansible_auto/config.rb +74 -33
- data/lib/vagrant/ansible_auto/errors.rb +30 -1
- data/lib/vagrant/ansible_auto/host.rb +123 -34
- data/lib/vagrant/ansible_auto/inventory.rb +196 -34
- data/lib/vagrant/ansible_auto/plugin.rb +23 -8
- data/lib/vagrant/ansible_auto/provisioner.rb +121 -79
- data/lib/vagrant/ansible_auto/util/config.rb +61 -0
- data/lib/vagrant/ansible_auto/util/hash_with_indifferent_access.rb +58 -0
- data/lib/vagrant/ansible_auto/util/keys.rb +49 -0
- data/lib/vagrant/ansible_auto/util/shell_quote.rb +24 -0
- data/lib/vagrant/ansible_auto/version.rb +2 -1
- data/lib/vagrant/ansible_auto.rb +15 -0
- data/locales/en.yml +34 -0
- data/spec/spec_helper.rb +5 -85
- data/spec/support/context.rb +111 -0
- data/spec/support/matchers.rb +45 -0
- data/spec/unit/vagrant/ansible_auto/config_spec.rb +72 -0
- data/spec/unit/vagrant/ansible_auto/host_spec.rb +131 -0
- data/spec/unit/vagrant/ansible_auto/inventory_spec.rb +349 -0
- data/spec/unit/vagrant/ansible_auto/provisioner_spec.rb +248 -0
- data/spec/unit/vagrant/ansible_auto/util/config_spec.rb +63 -0
- data/spec/unit/vagrant/ansible_auto/util/keys_spec.rb +66 -0
- data/vagrant-ansible_auto.gemspec +6 -4
- data/vagrant-spec.config.rb +3 -0
- data/yard/extensions.rb +45 -0
- metadata +36 -11
- data/Vagrantfile2 +0 -4
- data/Vagrantfile3 +0 -8
- data/Vagrantfile4 +0 -31
- data/lib/vagrant/ansible_auto/cap/guest/posix/bash_installed.rb +0 -30
- data/lib/vagrant/ansible_auto/util.rb +0 -24
- data/spec/vagrant/ansible_auto/host_spec.rb +0 -43
- data/spec/vagrant/ansible_auto/inventory_spec.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4bb6c4215e1b0c8f9aeb522426dd522a743e26
|
4
|
+
data.tar.gz: 2921234cbcc88bda96d0bde9e1d8ca456f36dbe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 500890578628075bea826662ef985ba8b9007de9454c17ca1078564124710cf7f09abb56ce171897674d0ca47d5a1846d7f653c1c81003feb90317775c606708
|
7
|
+
data.tar.gz: e8d3f80ab494637c2267da56e8aee5d1b67eea39f2e549e3fd8807a2223f75dba0a50256ddf7957e440645ffa07531ce5c6343ef9e3d369d7e2cc27e59e545e5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## Next Version (Unreleased)
|
2
|
+
|
3
|
+
FEATURES:
|
4
|
+
|
5
|
+
IMPROVEMENTS:
|
6
|
+
|
7
|
+
BUG FIXES:
|
8
|
+
|
9
|
+
## 0.2.1 (July 29, 2017)
|
10
|
+
|
11
|
+
BUG FIXES:
|
12
|
+
|
13
|
+
- Fix build errors by committing updated `Gemfile.lock` with version bump
|
14
|
+
|
15
|
+
## 0.2.1 (July 29, 2017)
|
16
|
+
|
17
|
+
FEATURES:
|
18
|
+
|
19
|
+
- Permit inserting the control machine's public key into the `authorized_keys`
|
20
|
+
file on managed machines, as an alternative to uploading the managed
|
21
|
+
machines' private keys to the control machine
|
22
|
+
- Add JSON output options to `vagrant ansible inventory`
|
23
|
+
|
24
|
+
IMPROVEMENTS:
|
25
|
+
|
26
|
+
- Add I18n support
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/mitchellh/vagrant-spec.git
|
3
|
+
revision: 2f0fb10862b2d19861c584be9d728080ba1f5d33
|
4
|
+
specs:
|
5
|
+
vagrant-spec (0.0.1)
|
6
|
+
childprocess (~> 0.6.0)
|
7
|
+
log4r (~> 1.1.9)
|
8
|
+
rspec (~> 2.14)
|
9
|
+
thor (~> 0.18.1)
|
10
|
+
|
11
|
+
GIT
|
12
|
+
remote: git://github.com/mitchellh/vagrant.git
|
13
|
+
revision: a7b228eb698352638270dc076d0385fa324ca187
|
14
|
+
specs:
|
15
|
+
vagrant (1.9.8.dev)
|
16
|
+
childprocess (~> 0.6.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
hashicorp-checkpoint (~> 0.1.1)
|
19
|
+
i18n (>= 0.6.0, <= 0.8.0)
|
20
|
+
listen (~> 3.1.5)
|
21
|
+
log4r (~> 1.1.9, < 1.1.11)
|
22
|
+
net-scp (~> 1.2.0)
|
23
|
+
net-sftp (~> 2.1)
|
24
|
+
net-ssh (~> 4.1.0)
|
25
|
+
rb-kqueue (~> 0.2.0)
|
26
|
+
rest-client (>= 1.6.0, < 3.0)
|
27
|
+
ruby_dep (<= 1.3.1)
|
28
|
+
wdm (~> 0.1.0)
|
29
|
+
winrm (~> 2.1)
|
30
|
+
winrm-elevated (~> 1.1)
|
31
|
+
winrm-fs (~> 1.0)
|
32
|
+
|
33
|
+
PATH
|
34
|
+
remote: .
|
35
|
+
specs:
|
36
|
+
vagrant-ansible_auto (0.2.1)
|
37
|
+
|
38
|
+
GEM
|
39
|
+
remote: https://rubygems.org/
|
40
|
+
specs:
|
41
|
+
ast (2.3.0)
|
42
|
+
builder (3.2.3)
|
43
|
+
cane (3.0.0)
|
44
|
+
parallel
|
45
|
+
childprocess (0.6.3)
|
46
|
+
ffi (~> 1.0, >= 1.0.11)
|
47
|
+
coderay (1.1.1)
|
48
|
+
coveralls (0.7.2)
|
49
|
+
multi_json (~> 1.3)
|
50
|
+
rest-client (= 1.6.7)
|
51
|
+
simplecov (>= 0.7)
|
52
|
+
term-ansicolor (= 1.2.2)
|
53
|
+
thor (= 0.18.1)
|
54
|
+
diff-lcs (1.3)
|
55
|
+
docile (1.1.5)
|
56
|
+
erubis (2.7.0)
|
57
|
+
ffi (1.9.18)
|
58
|
+
gssapi (1.2.0)
|
59
|
+
ffi (>= 1.0.1)
|
60
|
+
gyoku (1.3.1)
|
61
|
+
builder (>= 2.1.2)
|
62
|
+
hashicorp-checkpoint (0.1.4)
|
63
|
+
httpclient (2.8.3)
|
64
|
+
i18n (0.8.0)
|
65
|
+
json (2.1.0)
|
66
|
+
listen (3.1.5)
|
67
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
68
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
69
|
+
ruby_dep (~> 1.2)
|
70
|
+
little-plugger (1.1.4)
|
71
|
+
log4r (1.1.10)
|
72
|
+
logging (2.2.2)
|
73
|
+
little-plugger (~> 1.1)
|
74
|
+
multi_json (~> 1.10)
|
75
|
+
method_source (0.8.2)
|
76
|
+
mime-types (3.1)
|
77
|
+
mime-types-data (~> 3.2015)
|
78
|
+
mime-types-data (3.2016.0521)
|
79
|
+
multi_json (1.12.1)
|
80
|
+
net-scp (1.2.1)
|
81
|
+
net-ssh (>= 2.6.5)
|
82
|
+
net-sftp (2.1.2)
|
83
|
+
net-ssh (>= 2.6.5)
|
84
|
+
net-ssh (4.1.0)
|
85
|
+
nori (2.6.0)
|
86
|
+
parallel (1.12.0)
|
87
|
+
parser (2.4.0.0)
|
88
|
+
ast (~> 2.2)
|
89
|
+
powerpack (0.1.1)
|
90
|
+
pry (0.10.4)
|
91
|
+
coderay (~> 1.1.0)
|
92
|
+
method_source (~> 0.8.1)
|
93
|
+
slop (~> 3.4)
|
94
|
+
rainbow (2.2.2)
|
95
|
+
rake
|
96
|
+
rake (10.5.0)
|
97
|
+
rb-fsevent (0.10.2)
|
98
|
+
rb-inotify (0.9.10)
|
99
|
+
ffi (>= 0.5.0, < 2)
|
100
|
+
rb-kqueue (0.2.5)
|
101
|
+
ffi (>= 0.5.0)
|
102
|
+
rest-client (1.6.7)
|
103
|
+
mime-types (>= 1.16)
|
104
|
+
rspec (2.99.0)
|
105
|
+
rspec-core (~> 2.99.0)
|
106
|
+
rspec-expectations (~> 2.99.0)
|
107
|
+
rspec-mocks (~> 2.99.0)
|
108
|
+
rspec-core (2.99.2)
|
109
|
+
rspec-expectations (2.99.2)
|
110
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
111
|
+
rspec-mocks (2.99.4)
|
112
|
+
rubocop (0.49.1)
|
113
|
+
parallel (~> 1.10)
|
114
|
+
parser (>= 2.3.3.1, < 3.0)
|
115
|
+
powerpack (~> 0.1)
|
116
|
+
rainbow (>= 1.99.1, < 3.0)
|
117
|
+
ruby-progressbar (~> 1.7)
|
118
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
119
|
+
ruby-progressbar (1.8.1)
|
120
|
+
ruby_dep (1.3.1)
|
121
|
+
rubyntlm (0.6.2)
|
122
|
+
rubyzip (1.2.1)
|
123
|
+
simplecov (0.14.1)
|
124
|
+
docile (~> 1.1.0)
|
125
|
+
json (>= 1.8, < 3)
|
126
|
+
simplecov-html (~> 0.10.0)
|
127
|
+
simplecov-html (0.10.1)
|
128
|
+
slop (3.6.0)
|
129
|
+
term-ansicolor (1.2.2)
|
130
|
+
tins (~> 0.8)
|
131
|
+
thor (0.18.1)
|
132
|
+
tins (0.13.2)
|
133
|
+
unicode-display_width (1.3.0)
|
134
|
+
wdm (0.1.1)
|
135
|
+
winrm (2.2.3)
|
136
|
+
builder (>= 2.1.2)
|
137
|
+
erubis (~> 2.7)
|
138
|
+
gssapi (~> 1.2)
|
139
|
+
gyoku (~> 1.0)
|
140
|
+
httpclient (~> 2.2, >= 2.2.0.2)
|
141
|
+
logging (>= 1.6.1, < 3.0)
|
142
|
+
nori (~> 2.0)
|
143
|
+
rubyntlm (~> 0.6.0, >= 0.6.1)
|
144
|
+
winrm-elevated (1.1.0)
|
145
|
+
winrm (~> 2.0)
|
146
|
+
winrm-fs (~> 1.0)
|
147
|
+
winrm-fs (1.0.1)
|
148
|
+
erubis (~> 2.7)
|
149
|
+
logging (>= 1.6.1, < 3.0)
|
150
|
+
rubyzip (~> 1.1)
|
151
|
+
winrm (~> 2.0)
|
152
|
+
yard (0.9.9)
|
153
|
+
|
154
|
+
PLATFORMS
|
155
|
+
ruby
|
156
|
+
|
157
|
+
DEPENDENCIES
|
158
|
+
bundler (~> 1.12.5)
|
159
|
+
cane
|
160
|
+
coveralls
|
161
|
+
pry
|
162
|
+
rake (~> 10.0)
|
163
|
+
rspec (~> 2.14)
|
164
|
+
rubocop
|
165
|
+
simplecov
|
166
|
+
vagrant!
|
167
|
+
vagrant-ansible_auto!
|
168
|
+
vagrant-spec!
|
169
|
+
yard
|
170
|
+
|
171
|
+
BUNDLED WITH
|
172
|
+
1.12.5
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Vagrant::AnsibleAuto
|
2
2
|
|
3
|
+
[](https://travis-ci.org/BaxterStockman/vagrant-ansible_auto)
|
4
|
+
[](https://gemnasium.com/BaxterStockman/vagrant-ansible_auto)
|
5
|
+
[](https://codeclimate.com/github/BaxterStockman/vagrant-ansible_auto)
|
6
|
+
[](https://coveralls.io/github/BaxterStockman/vagrant-ansible_auto?branch=travis)
|
7
|
+
[](https://rubygems.org/gems/vagrant-ansible_auto)
|
8
|
+
|
3
9
|
This Vagrant plugin provides the `ansible_auto` provisioner that automatically
|
4
10
|
sets up the provisioned guest as an Ansible control machine for the nodes
|
5
11
|
defined in your Vagrantfile. It also provides the `vagrant ansible` subcommand
|
@@ -47,9 +53,9 @@ end
|
|
47
53
|
Running `vagrant ansible inventory` will print this Ansible inventory:
|
48
54
|
|
49
55
|
```ini
|
50
|
-
ansible-test-worker-1 ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/
|
51
|
-
ansible-test-worker-2 ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=/home/
|
52
|
-
ansible-test-control ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2201 ansible_ssh_private_key_file=/home/
|
56
|
+
ansible-test-worker-1 ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/user/vagrant/cluster/.vagrant/machines/ansible-test-worker-1/virtualbox/private_key
|
57
|
+
ansible-test-worker-2 ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=/home/user/vagrant/cluster/.vagrant/machines/ansible-test-worker-2/virtualbox/private_key
|
58
|
+
ansible-test-control ansible_ssh_user=vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2201 ansible_ssh_private_key_file=/home/user/vagrant/cluster/.vagrant/machines/ansible-test-control/virtualbox/private_key
|
53
59
|
[control]
|
54
60
|
ansible-test-control
|
55
61
|
[worker]
|
@@ -60,6 +66,9 @@ control
|
|
60
66
|
worker
|
61
67
|
```
|
62
68
|
|
69
|
+
You can print the inventory as compact JSON by providing the `--json` flag or
|
70
|
+
as pretty JSON by providing the `--pretty` flag.
|
71
|
+
|
63
72
|
### Provisioning
|
64
73
|
|
65
74
|
The `ansible_auto` provisioner is an augmented version of the
|
@@ -75,7 +84,7 @@ Vagrant.configure(2) do |config|
|
|
75
84
|
# [control]
|
76
85
|
# ansible-control
|
77
86
|
ansible.groups = {
|
78
|
-
'control' => %(ansible-control)
|
87
|
+
'control' => %w(ansible-control)
|
79
88
|
}
|
80
89
|
|
81
90
|
# Will show up in inventory as
|
@@ -87,14 +96,14 @@ Vagrant.configure(2) do |config|
|
|
87
96
|
|
88
97
|
# Will show up in inventory as
|
89
98
|
# [dev:vars]
|
90
|
-
#
|
99
|
+
# git_branch = devel
|
91
100
|
ansible.vars = {
|
92
101
|
'dev' => {
|
93
|
-
'
|
102
|
+
'git_branch' => 'devel'
|
94
103
|
}
|
95
104
|
}
|
96
105
|
|
97
|
-
# Enable or disable `StrictHostKeyChecking` SSH option.
|
106
|
+
# Enable or disable the `StrictHostKeyChecking` SSH option.
|
98
107
|
# Disabled by default.
|
99
108
|
ansible.strict_host_key_checking = false
|
100
109
|
|
@@ -104,21 +113,53 @@ Vagrant.configure(2) do |config|
|
|
104
113
|
|
105
114
|
# The number of seconds to delay between connection attempts.
|
106
115
|
ansible.host_connect_sleep = 5
|
116
|
+
|
117
|
+
# When true, insert the public key of the SSH user for the control
|
118
|
+
# machine (the machine that will run `ansible-playbook`) into the
|
119
|
+
# authorized_keys files of the SSH users on managed machines. Enabled by
|
120
|
+
# default.
|
121
|
+
ansible.insert_control_machine_public_key = false
|
122
|
+
|
123
|
+
# When true, upload the private keys for the SSH users of managed
|
124
|
+
# machines to a temporary location on the control machine, using these
|
125
|
+
# keys as the values of `ansible_ssh_private_key_file` in the generated
|
126
|
+
# inventory. Disabled by default, unless
|
127
|
+
# `insert_control_machine_public_key` is disabled.
|
128
|
+
ansible.upload_inventory_host_private_keys = true
|
107
129
|
end
|
108
130
|
end
|
109
131
|
end
|
110
132
|
```
|
111
133
|
|
134
|
+
#### Public Key Authentication
|
135
|
+
|
112
136
|
Each guest provisioned with `ansible_auto` will be set up as an Ansible
|
113
137
|
control machine with the ability to connect to other guests defined in the
|
114
|
-
`Vagrantfile`. This is facilitated by
|
115
|
-
|
116
|
-
|
117
|
-
|
138
|
+
`Vagrantfile`. This is facilitated by either:
|
139
|
+
|
140
|
+
- Inserting the public key of the control machine's SSH user into the
|
141
|
+
`authorized_keys` file of the SSH user on each of the managed machines (other
|
142
|
+
than the control machine itself). This is what happens when the option
|
143
|
+
`insert_control_machine_public_key` is in effect.
|
144
|
+
- Uploading the private keys of each guest to a temporary path on the control
|
145
|
+
machine and assigning this path as the hostvar `ansible_ssh_private_key_file`
|
146
|
+
to the relevant host in the generated inventory. This is what happens when
|
147
|
+
the option `upload_inventory_host_private_keys` is in effect.
|
148
|
+
|
149
|
+
`insert_control_machine_public_key` takes precedence over
|
150
|
+
`upload_inventory_host_private_keys`, so public key insertion will be used if
|
151
|
+
both options are set to `true`.
|
152
|
+
|
153
|
+
#### Targeted Machines
|
154
|
+
|
155
|
+
By default, the `ansible_auto` provisioner targets all machines defined in the
|
156
|
+
inventory by setting the provisioner option `ansible.limit` to `"*"`. This is
|
157
|
+
different than the core `ansible_local` provisioner, which by default targets
|
158
|
+
only the guest for which the provisioner was defined.
|
118
159
|
|
119
160
|
## Contributing
|
120
161
|
|
121
|
-
1. Fork it ( https://github.com/
|
162
|
+
1. Fork it ( https://github.com/BaxterStockman/vagrant-ansible_auto/fork )
|
122
163
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
123
164
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
124
165
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "bundler/gem_tasks"
|
3
2
|
|
4
|
-
require
|
5
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
6
|
-
t.ruby_opts = "-w"
|
7
|
-
end
|
3
|
+
require 'bundler/gem_tasks'
|
8
4
|
|
9
|
-
require
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
10
9
|
RuboCop::RakeTask.new
|
11
10
|
|
12
|
-
|
11
|
+
require 'yard'
|
12
|
+
YARD::Rake::YardocTask.new
|
13
|
+
|
14
|
+
task default: %i[rubocop spec]
|
data/TODO.md
CHANGED
@@ -6,3 +6,17 @@
|
|
6
6
|
- Util::ScopedHashOverride for the key conversions done in Host?
|
7
7
|
- Util::HashWithIndifferentAccess for Host?
|
8
8
|
- default vaues for arguments to attr_writer methods in `Inventory`
|
9
|
+
- Make sure error messages use `channel: :error`
|
10
|
+
- Safe method for expansion of remote paths
|
11
|
+
- Check that the version of Ansible on the control machine supports the `local`
|
12
|
+
connection type
|
13
|
+
- (Optionally) remove inventory host private keys from the control machine
|
14
|
+
after `ansible-playbook` runs
|
15
|
+
- Delegate config methods `groups=`, `children=`, and `vars=` to the
|
16
|
+
`inventory` instance variable (for auto-vivification of the various hashes)
|
17
|
+
|
18
|
+
## I1*8n
|
19
|
+
|
20
|
+
- Command line option usage
|
21
|
+
- Error message in `command/root.rb` (and any other instances of
|
22
|
+
`@env.ui#method`)
|
data/Vagrantfile
CHANGED
@@ -1,23 +1,45 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
Vagrant.configure(2) do |config|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
config.vm.box = 'hashicorp/precise64'
|
3
|
+
|
4
|
+
(1..2).each do |i|
|
5
|
+
name = "ansible-test-worker-#{i}"
|
6
|
+
|
7
|
+
config.vm.define name do |machine|
|
8
|
+
machine.vm.provider :docker do |d|
|
9
|
+
d.image = 'baxterstockman/minideb-vagrant'
|
10
|
+
d.has_ssh = true
|
11
11
|
end
|
12
|
+
|
13
|
+
machine.ansible.groups = {
|
14
|
+
'worker' => name,
|
15
|
+
'cluster:children' => ['worker']
|
16
|
+
}
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
config.vm.define 'ansible-test-control' do |machine|
|
21
|
+
machine.vm.provider :docker do |d|
|
22
|
+
d.image = 'baxterstockman/minideb-vagrant'
|
23
|
+
d.has_ssh = true
|
24
|
+
end
|
25
|
+
|
26
|
+
machine.vm.provision :ansible_auto do |ansible|
|
27
|
+
ansible.limit = '*'
|
28
|
+
ansible.playbook = 'playbooks/test.yml'
|
29
|
+
end
|
30
|
+
|
31
|
+
machine.ansible.groups = {
|
32
|
+
'control' => ['ansible-test-control'],
|
33
|
+
'cluster:children' => ['control']
|
34
|
+
}
|
35
|
+
end
|
18
36
|
|
19
|
-
config.ansible.
|
20
|
-
'
|
21
|
-
|
37
|
+
config.ansible.vars = {
|
38
|
+
'control' => {
|
39
|
+
'role' => 'ansible-control'
|
40
|
+
},
|
41
|
+
'worker' => {
|
42
|
+
'role' => 'ansible-worker'
|
43
|
+
}
|
22
44
|
}
|
23
45
|
end
|
@@ -1,14 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'uri'
|
3
4
|
|
5
|
+
require 'vagrant/ansible_auto/util/shell_quote'
|
6
|
+
|
4
7
|
module VagrantPlugins
|
5
8
|
module AnsibleAuto
|
6
9
|
module Cap
|
7
10
|
module Guest
|
8
11
|
module POSIX
|
12
|
+
# Capability class for checking whether a port is open on a given
|
13
|
+
# host
|
14
|
+
# @note requires Bash to be installed on the target machine
|
9
15
|
class CheckOpenPort
|
16
|
+
extend VagrantPlugins::AnsibleAuto::Util::ShellQuote
|
17
|
+
|
10
18
|
class << self
|
11
|
-
|
19
|
+
# Check whether a port is open
|
20
|
+
# @param [Vagrant::Machine] machine a guest machine
|
21
|
+
# @param [String] host hostname whose port will be checked
|
22
|
+
# @param [Integer] port port number to check
|
23
|
+
# @param [String] proto the protocol to use
|
24
|
+
# @return [Boolean] if a valid hostname and port were provided,
|
25
|
+
# whether the specified port is open on the specified host
|
26
|
+
# @return [nil] if hostname or port were not valid, or if Bash is
|
27
|
+
# not available on the target machine
|
28
|
+
def port_open?(machine, host, port, proto = 'tcp')
|
12
29
|
return nil unless machine.communicate.test('bash')
|
13
30
|
|
14
31
|
# Check that we got a valid URI by constructing a URI object
|
@@ -22,8 +39,10 @@ module VagrantPlugins
|
|
22
39
|
return nil
|
23
40
|
end
|
24
41
|
|
25
|
-
|
26
|
-
|
42
|
+
return false if uri.host.nil? || uri.port.nil?
|
43
|
+
|
44
|
+
target = shellescape(File.join('/dev/', proto, uri.host, uri.port.to_s))
|
45
|
+
machine.communicate.test("read < #{target}", shell: 'bash')
|
27
46
|
end
|
28
47
|
end
|
29
48
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require 'vagrant/ansible_auto/util/shell_quote'
|
3
4
|
|
4
5
|
module VagrantPlugins
|
5
6
|
module AnsibleAuto
|
6
7
|
module Cap
|
7
8
|
module Guest
|
8
9
|
module POSIX
|
10
|
+
# Check whether an executable is installed
|
9
11
|
class ExecutableInstalled
|
12
|
+
extend Util::ShellQuote
|
13
|
+
|
10
14
|
class << self
|
15
|
+
# @param [Machine] machine a guest machine
|
16
|
+
# @param [#to_s] executable name or path of an executable
|
17
|
+
# @return [Boolean] whether the executable exists and has the
|
18
|
+
# executable bit set
|
11
19
|
def executable_installed?(machine, executable)
|
12
|
-
machine.communicate.test(%[test -x "$(command -v #{executable
|
20
|
+
machine.communicate.test(%[test -x "$(command -v '#{shellescape(executable)}')"], error_check: false)
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'set'
|
3
2
|
|
4
3
|
module VagrantPlugins
|
5
4
|
module AnsibleAuto
|
6
5
|
module Cap
|
7
6
|
module Guest
|
8
7
|
module POSIX
|
8
|
+
# List gateway addresses for the interfaces on a machine
|
9
9
|
class GatewayAddresses
|
10
10
|
class << self
|
11
|
+
# @param [Machine] machine a guest machine
|
12
|
+
# @return [Array<String>] a list of the gateway IP addresses for
|
13
|
+
# the machine
|
11
14
|
def gateway_addresses(machine)
|
12
|
-
with_default_gateway_addresses(machine).to_a.compact
|
15
|
+
with_default_gateway_addresses(machine).to_a.compact.uniq
|
13
16
|
end
|
14
17
|
|
15
18
|
private
|
@@ -17,39 +20,21 @@ module VagrantPlugins
|
|
17
20
|
def with_default_gateway_addresses(machine)
|
18
21
|
return enum_for(__method__, machine) unless block_given?
|
19
22
|
|
20
|
-
seen_addresses = Set.new
|
21
|
-
yield_unseen_address = lambda do |a|
|
22
|
-
yield a unless seen_addresses.include? a
|
23
|
-
seen_addresses << a
|
24
|
-
end
|
25
|
-
|
26
23
|
machine.communicate.execute('ip route show', error_check: false) do |type, data|
|
27
24
|
if type == :stdout
|
28
|
-
data.
|
29
|
-
if line.start_with?('default')
|
30
|
-
yield_unseen_address.call(line.split[2])
|
31
|
-
end
|
32
|
-
end
|
25
|
+
data.each_line { |l| yield l.split[2] if l.start_with? 'default' }
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
36
29
|
machine.communicate.execute('route -n', error_check: false) do |type, data|
|
37
30
|
if type == :stdout
|
38
|
-
data.
|
39
|
-
if line.start_with?('0.0.0.0')
|
40
|
-
yield_unseen_address.call(line.split[1])
|
41
|
-
end
|
42
|
-
end
|
31
|
+
data.each_line { |l| yield l.split[1] if l.start_with? '0.0.0.0' }
|
43
32
|
end
|
44
33
|
end
|
45
34
|
|
46
35
|
machine.communicate.execute('netstat -rn', error_check: false) do |type, data|
|
47
36
|
if type == :stdout
|
48
|
-
data.
|
49
|
-
if line.start_with?('0.0.0.0')
|
50
|
-
yield_unseen_address.call(line.split[1])
|
51
|
-
end
|
52
|
-
end
|
37
|
+
data.each_line { |l| yield l.split[1] if l.start_with? '0.0.0.0' }
|
53
38
|
end
|
54
39
|
end
|
55
40
|
end
|
@@ -1,17 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'vagrant/ansible_auto/util/shell_quote'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module AnsibleAuto
|
5
7
|
module Cap
|
6
8
|
module Guest
|
7
9
|
module POSIX
|
10
|
+
# Create a private key
|
8
11
|
class PrivateKey
|
12
|
+
extend Util::ShellQuote
|
13
|
+
|
9
14
|
class << self
|
15
|
+
# @param [Vagrant::Machine] machine a guest machine
|
16
|
+
# @param [#to_s] path the output path for the generated private
|
17
|
+
# key
|
18
|
+
# @param [String] type the type of key to generate. Takes any
|
19
|
+
# valid type to the +ssh-keygen+ utility's +-t+ option
|
20
|
+
# @param [String] bits the bits of entropy. Takes any value
|
21
|
+
# valid for the +ssh-keygen+ utility's +-b+ option
|
22
|
+
# @return [nil] if +ssh-keygen+ is not available on the machine
|
23
|
+
# @return [Integer] the exit code of the remote command
|
10
24
|
def generate_private_key(machine, path, type = 'rsa', bits = '2048')
|
11
25
|
return unless machine.guest.capability?(:executable_installed?) \
|
12
26
|
&& machine.guest.capability(:executable_installed?, 'ssh-keygen')
|
13
27
|
|
14
|
-
|
28
|
+
cmd = "ssh-keygen -t #{shellescape(type)} -b #{shellescape(bits)} -C 'Vagrant-generated keypair' -f #{shellescape(path)}"
|
29
|
+
machine.communicate.execute(cmd)
|
15
30
|
end
|
16
31
|
end
|
17
32
|
end
|
@@ -1,24 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'vagrant/ansible_auto/util/shell_quote'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module AnsibleAuto
|
5
7
|
module Cap
|
6
8
|
module Guest
|
7
9
|
module POSIX
|
8
|
-
|
10
|
+
# Grab a public key from a guest machine
|
11
|
+
class PublicKey
|
12
|
+
extend Util::ShellQuote
|
13
|
+
|
9
14
|
class << self
|
15
|
+
# @param [Vagrant::Machine] machine a guest machine
|
16
|
+
# @param [#to_s] path path to the public key
|
17
|
+
# @return [nil] if the public key file cannot be read
|
18
|
+
# @return [String if the public key file can be read, its
|
19
|
+
# contents
|
10
20
|
def fetch_public_key(machine, path)
|
11
21
|
return unless machine.guest.capability?(:executable_installed?) \
|
12
22
|
&& machine.guest.capability(:executable_installed?, 'ssh-keygen')
|
13
23
|
|
14
|
-
# TODO: handle bad status
|
15
24
|
public_key = ''
|
16
|
-
|
25
|
+
exit_status = machine.communicate.execute("ssh-keygen -f #{shellescape(path)} -y", error_check: false) do |data_type, data|
|
17
26
|
public_key += data if data_type == :stdout
|
18
27
|
end
|
19
28
|
|
29
|
+
return if public_key.empty? || !exit_status.zero?
|
30
|
+
|
20
31
|
public_key
|
21
32
|
end
|
33
|
+
|
34
|
+
def authorized_key?(machine, content, path = '~/.ssh/authorized_keys')
|
35
|
+
machine.communicate.test("grep -q -x -F '#{shellescape(content.chomp)}' #{shellescape(path)}")
|
36
|
+
end
|
22
37
|
end
|
23
38
|
end
|
24
39
|
end
|