vagrant-flow 1.0.7 → 1.0.8
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/README.md +70 -10
- data/create_sample_multiinit_input-file.rb +30 -0
- data/lib/vagrant-flow/command/ansibleinventory.rb +258 -0
- data/lib/vagrant-flow/command/multiinit.rb +155 -0
- data/lib/vagrant-flow/command/root.rb +70 -0
- data/lib/vagrant-flow/plugin.rb +13 -5
- data/lib/vagrant-flow/templates/multiinit.erb +29 -0
- data/lib/vagrant-flow/version.rb +1 -1
- metadata +6 -2
- data/lib/vagrant-flow/command.rb +0 -257
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01e8dbb3fea3a1fbb847bb1427a22100522c319e
|
|
4
|
+
data.tar.gz: ea5cdedd8094a8064acc02016719784f93b72fb6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 281baccfccb78752d0181fcd23b7cb0db8e05950809e0e0689974a0c87b340a5dafe069047e05586789b3166c5198b44cc4be741c63c6f3210970dc9e9bbb64e
|
|
7
|
+
data.tar.gz: fb1543c977bcb2f86f89f1d9ea95128ebbf240590316e80aaf85851cfe772cfddde11624d9036edd1ab07b2327441c70727d34e1217e3f9f3157eefc23f3a2a9
|
data/README.md
CHANGED
|
@@ -22,9 +22,12 @@ Or install it yourself as:
|
|
|
22
22
|
|
|
23
23
|
$ gem install vagrant-flow
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
* * *
|
|
26
|
+
|
|
27
|
+
# Usage
|
|
28
|
+
## ansibleinventory
|
|
26
29
|
```
|
|
27
|
-
Usage: vagrant
|
|
30
|
+
Usage: vagrant flow ansibleinventory [-hgpq]
|
|
28
31
|
This plugin looks for groupconfig.yml as the default configuration
|
|
29
32
|
Do not use -p and -g options together!
|
|
30
33
|
|
|
@@ -34,31 +37,31 @@ Do not use -p and -g options together!
|
|
|
34
37
|
-h, --help (Optional) Print this help
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
#### Example usages of ansibleinventory
|
|
38
41
|
This will look for a file in the pwd named groupconfig.yml and attempt to make the inventory
|
|
39
42
|
```
|
|
40
|
-
vagrant
|
|
43
|
+
vagrant flow ansibleinventory
|
|
41
44
|
```
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
|
|
45
48
|
This will look for a file in the pwd named myOwnGroupConfig.yml and attempt to make the inventory
|
|
46
49
|
```
|
|
47
|
-
vagrant
|
|
50
|
+
vagrant flow ansibleinventory -g myOwnGroupConfig.yml
|
|
48
51
|
```
|
|
49
52
|
|
|
50
53
|
|
|
51
54
|
|
|
52
55
|
This will parse the vagrant file for ansible group configs
|
|
53
56
|
```
|
|
54
|
-
vagrant
|
|
57
|
+
vagrant flow ansibleinventory -p
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
|
|
58
61
|
|
|
59
62
|
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
### Use case
|
|
62
65
|
```
|
|
63
66
|
#Bring up your vagrant machines
|
|
64
67
|
vagrant up
|
|
@@ -67,8 +70,6 @@ vagrant ansible-inventory
|
|
|
67
70
|
#point ansible-playbook to the generated vagrant-flow_ansible_inventory, and point them to whatever playbook you'd like
|
|
68
71
|
ansible-playbook -i path/to/vagrant-flow_ansible_inventory my_playbook.yml
|
|
69
72
|
```
|
|
70
|
-
## Usage Expectations
|
|
71
|
-
#### Don't mix the -p and -g options. Unexpected things will happen.
|
|
72
73
|
|
|
73
74
|
Example groupconfig.yml file (for use with no optional command line arguments or by pointing to non-default file with -g option)
|
|
74
75
|
```
|
|
@@ -117,7 +118,66 @@ Example playbook.yml to use after ansible-inventory has run with command `ansibl
|
|
|
117
118
|
roles:
|
|
118
119
|
- apache
|
|
119
120
|
```
|
|
121
|
+
* * *
|
|
122
|
+
## multiinit
|
|
123
|
+
```
|
|
124
|
+
Usage: vagrant flow multiinit [-hgliq]
|
|
125
|
+
This looks for multiinit.yml as the default configuration
|
|
126
|
+
|
|
127
|
+
-g FILEPATH, (Optional) YAML file containing vagrant cloud config
|
|
128
|
+
--vagrant_multiinit_config_file
|
|
129
|
+
-l hostname:cloud/location,hostname2:cloud/location2,hostname3:cloud/location3,
|
|
130
|
+
--list List of cloud config parameters
|
|
131
|
+
-i, --vboxintnet NAME (Optional) Custom virtualbox__intnet name for private network
|
|
132
|
+
-q, --quiet (Optional) Suppress output to STDOUT and STDERR
|
|
133
|
+
-h, --help Print this help
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Example usages of multiinit
|
|
137
|
+
This will look for a file in the pwd named multiinit.yml and attempt to make the Vagrantfile
|
|
138
|
+
```
|
|
139
|
+
vagrant flow multiinit
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
This will look for a file in the pwd named myOwnGroupConfig.yml and attempt to make the inventory
|
|
145
|
+
```
|
|
146
|
+
vagrant flow multiinit -g myOwnMultiInitConfig.yml
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
This will read in from the command line a list of [vm_name]:[url] combinations. It MUST follow the following format. The -i option will also set the virtualbox__intnet name to a custom option ("virtualboxprivatenet" in this case)
|
|
152
|
+
```
|
|
153
|
+
vagrant flow multiinit -l boxname1:demandcube/centos-65_x86_64-VB-4.3.8,boxname2:demandcube/centos-65_x86_65-VB-4.3.8,box3:provider/boxname -i virtualboxprivatenet
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### Use case
|
|
158
|
+
```
|
|
159
|
+
#Create your multi-box Vagrantfile
|
|
160
|
+
vagrant flow multiinit
|
|
161
|
+
#Launch the boxes
|
|
162
|
+
vagrant up
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Example multiinitconfig.yml file (for use with no optional command line arguments or by pointing to non-default file with -g option). The format of this yaml file MUST be followed, but can easily be expanded to include more of fewer machines
|
|
166
|
+
```
|
|
167
|
+
---
|
|
168
|
+
:intnetName: neverwinterDP
|
|
169
|
+
machines:
|
|
170
|
+
- name: machine1
|
|
171
|
+
url: demandcube/centos-65_x86_64-VB-4.3.8
|
|
172
|
+
- name: server1
|
|
173
|
+
url: demandcube/centos-64_x86_64-VB-4.3.8
|
|
174
|
+
- name: jenkinstestmachine
|
|
175
|
+
url: demandcube/centos-65_x86_64-VB-4.3.8
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
|
|
120
179
|
|
|
180
|
+
* * *
|
|
121
181
|
|
|
122
182
|
## Contributing
|
|
123
183
|
|
|
@@ -157,7 +217,7 @@ rake release
|
|
|
157
217
|
|
|
158
218
|
# install for real from the repo
|
|
159
219
|
|
|
160
|
-
vagrant plugin vagrant-flow
|
|
220
|
+
vagrant plugin install vagrant-flow
|
|
161
221
|
```
|
|
162
222
|
|
|
163
223
|
# Background Research
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
###This shows how to make a valid configuration file in YAML format for vagrant-flow to consume with the ansible-inventory command
|
|
6
|
+
x = {
|
|
7
|
+
:intnetName=>"neverwinterDP",
|
|
8
|
+
"machines" => [
|
|
9
|
+
{"name"=>"sparkngin1", "url"=>"demandcube/centos-65_x86_64-VB-4.3.8"},
|
|
10
|
+
{"name"=>"sparkngin2", "url"=>"demandcube/centos-65_x86_64-VB-4.3.8"},
|
|
11
|
+
{"name"=>"jenkinsdp", "url"=>"demandcube/centos-65_x86_64-VB-4.3.8"},
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
File.open('multiinitconfig.yml', 'w') {|f|
|
|
17
|
+
f.write x.to_yaml
|
|
18
|
+
}
|
|
19
|
+
rescue
|
|
20
|
+
warn "Could not write file multiinit.yml"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
y = YAML.load(x.to_yaml)
|
|
25
|
+
|
|
26
|
+
y.each {|key,value|
|
|
27
|
+
puts key
|
|
28
|
+
puts value
|
|
29
|
+
puts "\n"
|
|
30
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
require "vagrant"
|
|
3
|
+
require "yaml"
|
|
4
|
+
|
|
5
|
+
module VagrantPlugins
|
|
6
|
+
module CommandVagrantFlow
|
|
7
|
+
module Command
|
|
8
|
+
class AnsibleInventory < Vagrant.plugin("2", :command)
|
|
9
|
+
|
|
10
|
+
# Builtin from Command class
|
|
11
|
+
# Must override to provide a description
|
|
12
|
+
def self.synopsis
|
|
13
|
+
"generates a ansible inventory file from the vagrant environment"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Builtin from Command class
|
|
18
|
+
# Must override to provide core functionality
|
|
19
|
+
def execute
|
|
20
|
+
|
|
21
|
+
machines_configs = {}
|
|
22
|
+
inventory_configs = {}
|
|
23
|
+
|
|
24
|
+
default_group_config_file = "groupconfig.yml"
|
|
25
|
+
options = {}
|
|
26
|
+
options[:destroy_on_error] = true
|
|
27
|
+
options[:parallel] = false
|
|
28
|
+
options[:provision_ignore_sentinel] = false
|
|
29
|
+
options[:quiet] = false
|
|
30
|
+
|
|
31
|
+
#Setting to read in a file other than default_group_config_File
|
|
32
|
+
options[:custom_config_file] = false
|
|
33
|
+
#Setting to parse the VAGRANTFILE's ansible group config
|
|
34
|
+
options[:vagrantFileAnsibleConfig] = false
|
|
35
|
+
|
|
36
|
+
#Parse option, look up OptionParser documentation
|
|
37
|
+
opts = OptionParser.new do |o|
|
|
38
|
+
# o.banner = "Usage: vagrant ansible-inventory [vm-name] [options] [-h]"
|
|
39
|
+
o.banner = "A NeverWinterDP technology from the Department of Badass.\n\n"+
|
|
40
|
+
"Usage: vagrant flow ansibleinventory [-hgpq]\nThis looks for groupconfig.yml as the default configuration\n"+
|
|
41
|
+
"Do not use -p and -g options together!"
|
|
42
|
+
o.separator ""
|
|
43
|
+
o.on("-g", "--group_config_file FILEPATH", "(Optional) YAML file containing group config") do |f|
|
|
44
|
+
options[:custom_config_file] = f
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
o.on("-p", "--vagrantfileparse", "(Optional) Read in the VAGRANTFILE's ansible group config") do |f|
|
|
48
|
+
options[:vagrantFileAnsibleConfig] = true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
o.on("-q", "--quiet", "(Optional) Suppress output to STDOUT and STDERR") do |f|
|
|
52
|
+
options[:quiet] = true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Parse the options # Builtin from the Command Class
|
|
58
|
+
# Will safely parse the arguments and
|
|
59
|
+
# Automatically detects -h for help
|
|
60
|
+
argv = parse_options(opts)
|
|
61
|
+
return if !argv
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# The following are already setup by the parent class
|
|
66
|
+
# @env
|
|
67
|
+
# @logger
|
|
68
|
+
# @argv
|
|
69
|
+
|
|
70
|
+
# Go over each VM and bring it up
|
|
71
|
+
@logger.debug("'ansible-inventory' created for the whole env")
|
|
72
|
+
|
|
73
|
+
#Initialize group_machines, the has containing group=>machinename configs
|
|
74
|
+
group_machines={}
|
|
75
|
+
|
|
76
|
+
#Get info about the vagrant boxes
|
|
77
|
+
with_target_vms(argv, :provider => options[:provider]) do |machine|
|
|
78
|
+
# @env.ui
|
|
79
|
+
# output methods: :ask, :detail, :warn, :error, :info, :output, :success
|
|
80
|
+
# https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb
|
|
81
|
+
|
|
82
|
+
ssh_info = machine.ssh_info
|
|
83
|
+
raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
|
|
84
|
+
|
|
85
|
+
variables = {
|
|
86
|
+
:host_key => options[:host] || machine.name || "vagrant",
|
|
87
|
+
:ssh_host => ssh_info[:host],
|
|
88
|
+
:ssh_port => ssh_info[:port],
|
|
89
|
+
:ssh_user => ssh_info[:username],
|
|
90
|
+
:private_key_path => ssh_info[:private_key_path],
|
|
91
|
+
:forward_agent => ssh_info[:forward_agent],
|
|
92
|
+
:forward_x11 => ssh_info[:forward_x11]
|
|
93
|
+
}
|
|
94
|
+
# Outputs to the stdout
|
|
95
|
+
|
|
96
|
+
inventory_configs = {
|
|
97
|
+
:vagrant_file_dir => machine.env.root_path,
|
|
98
|
+
:vagrant_flow_file => machine.env.root_path.join("vagrant-flow_ansible_inventory")
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
machines_configs[variables[:host_key]]= variables
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#Hash containing group/machine configuration
|
|
105
|
+
group_machines={}
|
|
106
|
+
#Determine group_machines based on what config options are passed in
|
|
107
|
+
#Read in config from vagrantfile's ansible config
|
|
108
|
+
if options[:vagrantFileAnsibleConfig] == true
|
|
109
|
+
provisioners = []
|
|
110
|
+
with_target_vms(argv, :provider => options[:provider]) do |machine|
|
|
111
|
+
#The provisioning information from teh vagrant file, this will contain our defined ansible groups
|
|
112
|
+
#Concatenate all the provisioner configs together
|
|
113
|
+
if machine.config.vm.provisioners
|
|
114
|
+
provisioners.concat(machine.config.vm.provisioners)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
#Since Vagrant machines will likely contain the same configs,
|
|
118
|
+
#Merge the config together to remove duplicate entries in our
|
|
119
|
+
#group/machine configuration
|
|
120
|
+
provisioners.each {|prov|
|
|
121
|
+
group_machines = group_machines.merge(prov.config.groups)
|
|
122
|
+
}
|
|
123
|
+
#Read in config from yaml file
|
|
124
|
+
else
|
|
125
|
+
#Use config option if specified
|
|
126
|
+
if options[:custom_config_file] != false
|
|
127
|
+
default_group_config_file = options[:custom_config_file]
|
|
128
|
+
end
|
|
129
|
+
begin
|
|
130
|
+
#Load YAML
|
|
131
|
+
group_machines = YAML.load_file(default_group_config_file)
|
|
132
|
+
rescue
|
|
133
|
+
#Give warning if no file could be found
|
|
134
|
+
if not options[:quiet]
|
|
135
|
+
warn "Could not open file: "+default_group_config_file.to_s
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# Outputs to the stdout
|
|
143
|
+
# @env.ui.info(machine.name)
|
|
144
|
+
|
|
145
|
+
# From - Vagrant::Util::SafePuts
|
|
146
|
+
# Template is erb
|
|
147
|
+
|
|
148
|
+
# Implementation picks the first key
|
|
149
|
+
# ssh_info[:private_key_path] returns an array
|
|
150
|
+
|
|
151
|
+
#outputs is going to contain our strings that are the formatted ansible configs
|
|
152
|
+
#the key will be the vm name, the value will the be formatted sring
|
|
153
|
+
outputs = {}
|
|
154
|
+
|
|
155
|
+
inventory_configs[:vagrant_flow_file].open('w') do |file|
|
|
156
|
+
machines_configs.each do |host, variables|
|
|
157
|
+
ansible_template = '<%= host_key %> ansible_ssh_host=<%= ssh_host %> ansible_ssh_port=<%= ssh_port %> ansible_ssh_user=<%= ssh_user %> ansible_ssh_private_key_file=<%= private_key_path[0] %> # Machine Name: <%= host_key %>'
|
|
158
|
+
outputs[variables[:host_key]] = Vagrant::Util::TemplateRenderer.render_string(ansible_template, variables)
|
|
159
|
+
#safe_puts(host_txt)
|
|
160
|
+
#file.write("#{host_txt}\n")
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#require 'pp'
|
|
165
|
+
#puts "PROVISIONERS"
|
|
166
|
+
#PP.pp(provisioners)
|
|
167
|
+
#puts "OUTPUTS"
|
|
168
|
+
#PP.pp(outputs)
|
|
169
|
+
#puts "\n\n"
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
inventory_configs[:vagrant_flow_file].open('w') do |file|
|
|
174
|
+
header_txt="# Generated by vagrant-flow, part of NeverwinterDP\n\n"
|
|
175
|
+
if not options[:quiet]
|
|
176
|
+
safe_puts(header_txt)
|
|
177
|
+
end
|
|
178
|
+
file.write(header_txt)
|
|
179
|
+
|
|
180
|
+
#Now we maps from our VAGRANTFILE defined groups in our provisioners.config.groups
|
|
181
|
+
#To our configuration strings we got from outputs
|
|
182
|
+
group_machines.each do |groupname,machines|
|
|
183
|
+
if not options[:quiet]
|
|
184
|
+
puts "["+groupname+"]\n"
|
|
185
|
+
end
|
|
186
|
+
file.write "["+groupname+"]\n"
|
|
187
|
+
machines.each do |machinename|
|
|
188
|
+
#if we match :children, then we have an ansible config that's
|
|
189
|
+
#pointing to another group, not a specific machine
|
|
190
|
+
if /:children/.match(groupname)
|
|
191
|
+
if not options[:quiet]
|
|
192
|
+
puts machinename
|
|
193
|
+
end
|
|
194
|
+
file.write machinename+"\n"
|
|
195
|
+
else
|
|
196
|
+
if not options[:quiet]
|
|
197
|
+
puts outputs[machinename.to_sym]+"\n"
|
|
198
|
+
end
|
|
199
|
+
file.write outputs[machinename.to_sym]+"\n"
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
if not options[:quiet]
|
|
203
|
+
puts "\n"
|
|
204
|
+
end
|
|
205
|
+
file.write "\n"
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
0
|
|
209
|
+
end # End Execute
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# Documentation reference
|
|
213
|
+
# http://docs.ansible.com/intro_inventory.html
|
|
214
|
+
|
|
215
|
+
#def setup_inventory_file(machine)
|
|
216
|
+
# return machine.config.inventory_path if machine.config.inventory_path
|
|
217
|
+
#
|
|
218
|
+
# ssh = machine.ssh_info
|
|
219
|
+
#
|
|
220
|
+
# generated_inventory_file =
|
|
221
|
+
# machine.env.root_path.join("vagrant-flow_ansible_inventory")
|
|
222
|
+
#
|
|
223
|
+
# generated_inventory_file.open('w') do |file|
|
|
224
|
+
# file.write("# Generated by Vagrant\n\n")
|
|
225
|
+
# file.write("#{machine.name} ansible_ssh_host=#{ssh[:host]} ansible_ssh_port=#{ssh[:port]}\n")
|
|
226
|
+
#
|
|
227
|
+
# # Write out groups information. Only include current
|
|
228
|
+
# # machine and its groups to avoid Ansible errors on
|
|
229
|
+
# # provisioning.
|
|
230
|
+
# groups_of_groups = {}
|
|
231
|
+
# included_groups = []
|
|
232
|
+
#
|
|
233
|
+
# config.groups.each_pair do |gname, gmembers|
|
|
234
|
+
# if gname.end_with?(":children")
|
|
235
|
+
# groups_of_groups[gname] = gmembers
|
|
236
|
+
# elsif gmembers.include?("#{machine.name}")
|
|
237
|
+
# included_groups << gname
|
|
238
|
+
# file.write("\n[#{gname}]\n")
|
|
239
|
+
# file.write("#{machine.name}\n")
|
|
240
|
+
# end
|
|
241
|
+
# end
|
|
242
|
+
#
|
|
243
|
+
# groups_of_groups.each_pair do |gname, gmembers|
|
|
244
|
+
# unless (included_groups & gmembers).empty?
|
|
245
|
+
# file.write("\n[#{gname}]\n")
|
|
246
|
+
# gmembers.each do |gm|
|
|
247
|
+
# file.write("#{gm}\n") if included_groups.include?(gm)
|
|
248
|
+
# end
|
|
249
|
+
# end
|
|
250
|
+
# end
|
|
251
|
+
# end
|
|
252
|
+
#
|
|
253
|
+
# return generated_inventory_file.to_s
|
|
254
|
+
#end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
require "vagrant"
|
|
2
|
+
require 'optparse'
|
|
3
|
+
require "yaml"
|
|
4
|
+
require 'erubis'
|
|
5
|
+
require "ipaddr"
|
|
6
|
+
|
|
7
|
+
module VagrantPlugins
|
|
8
|
+
module CommandVagrantFlow
|
|
9
|
+
module Command
|
|
10
|
+
class MultiInit < Vagrant.plugin("2", :command)
|
|
11
|
+
|
|
12
|
+
# Builtin from Command class
|
|
13
|
+
# Must override to provide a description
|
|
14
|
+
def self.synopsis
|
|
15
|
+
"Grabs a multitude of vagrant cloud boxes"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Builtin from Command class
|
|
20
|
+
# Must override to provide core functionality
|
|
21
|
+
def execute
|
|
22
|
+
default_group_config_file = "multiinitconfig.yml"
|
|
23
|
+
options = {}
|
|
24
|
+
options[:destroy_on_error] = true
|
|
25
|
+
options[:parallel] = false
|
|
26
|
+
options[:provision_ignore_sentinel] = false
|
|
27
|
+
options[:quiet] = false
|
|
28
|
+
|
|
29
|
+
#Default virtualbox__intnet name for private network
|
|
30
|
+
options[:vboxintnet] = "neverwinterDP"
|
|
31
|
+
|
|
32
|
+
#Setting to read in a file other than default_group_config_File
|
|
33
|
+
options[:vagrant_cloud_config_file] = false
|
|
34
|
+
|
|
35
|
+
#Parse option, look up OptionParser documentation
|
|
36
|
+
opts = OptionParser.new do |o|
|
|
37
|
+
# o.banner = "Usage: vagrant ansible-inventory [vm-name] [options] [-h]"
|
|
38
|
+
o.banner = "A NeverWinterDP technology from the Department of Badass.\n\n"+
|
|
39
|
+
"Usage: vagrant flow multiinit [-hgliq]\nThis looks for multiinit.yml as the default configuration\n"
|
|
40
|
+
o.separator ""
|
|
41
|
+
o.on("-g", "--vagrant_multiinit_config_file FILEPATH", "(Optional) YAML file containing vagrant cloud config") do |f|
|
|
42
|
+
options[:vagrant_cloud_config_file] = f
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
o.on( '-l', '--list hostname:cloud/location,hostname2:cloud/location2,hostname3:cloud/location3', Array, "List of cloud config parameters" ) do|f|
|
|
46
|
+
options[:vagrant_cloud_list] = f
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
o.on("-i", "--vboxintnet NAME", "(Optional) Custom virtualbox__intnet name for private network") do |f|
|
|
50
|
+
options[:vboxintnet] = f
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
o.on("-q", "--quiet", "(Optional) Suppress output to STDOUT and STDERR") do |f|
|
|
54
|
+
options[:quiet] = true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Parse the options # Builtin from the Command Class
|
|
60
|
+
# Will safely parse the arguments and
|
|
61
|
+
# Automatically detects -h for help
|
|
62
|
+
argv = parse_options(opts)
|
|
63
|
+
return if !argv
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#If no options are given, set the config file to the default
|
|
67
|
+
#and continue on our merry way
|
|
68
|
+
if not options[:vagrant_cloud_config_file] and not options[:vagrant_cloud_list]
|
|
69
|
+
options[:vagrant_cloud_config_file] = default_group_config_file
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#Get machine configs from config file or from command line
|
|
73
|
+
content = {}
|
|
74
|
+
if options[:vagrant_cloud_config_file]
|
|
75
|
+
begin
|
|
76
|
+
#Load YAML
|
|
77
|
+
content = YAML.load_file(options[:vagrant_cloud_config_file])
|
|
78
|
+
rescue
|
|
79
|
+
#Give warning if no file could be found
|
|
80
|
+
if not options[:quiet]
|
|
81
|
+
warn "Could not open file: "+options[:vagrant_cloud_config_file].to_s
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#Set intnetName if its not in the config
|
|
86
|
+
if not content.has_key?(:intnetName)
|
|
87
|
+
content[:intnetName]=options[:vboxintnet]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#Read in command line config
|
|
93
|
+
if options[:vagrant_cloud_list]
|
|
94
|
+
machines = []
|
|
95
|
+
options[:vagrant_cloud_list].each {|item|
|
|
96
|
+
split = item.split(":")
|
|
97
|
+
machines.push({
|
|
98
|
+
"name"=>split[0],
|
|
99
|
+
"url"=>split[1],
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
content = {
|
|
103
|
+
:intnetName=>options[:vboxintnet],
|
|
104
|
+
"machines" => machines,
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
#Bail out here if content is fubar
|
|
109
|
+
if not content.has_key?("machines")
|
|
110
|
+
return
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#Set IP's for private network
|
|
114
|
+
#Start at 192.168.1.0 and increment up
|
|
115
|
+
#using the IPAddr class
|
|
116
|
+
ip= IPAddr.new("192.168.1.0")
|
|
117
|
+
content["machines"].each {|machine|
|
|
118
|
+
ip = IPAddr.new(ip.to_s).succ
|
|
119
|
+
|
|
120
|
+
#If IP ends in x.x.x.0 or x.x.x.1, keep going one more
|
|
121
|
+
#to avoid conflicts with routers/gateways/etc
|
|
122
|
+
if ip.to_s.split(//).last(2) == [".","0"]
|
|
123
|
+
ip = IPAddr.new(ip.to_s).succ
|
|
124
|
+
end
|
|
125
|
+
if ip.to_s.split(//).last(2) == [".","1"]
|
|
126
|
+
ip = IPAddr.new(ip.to_s).succ
|
|
127
|
+
end
|
|
128
|
+
machine["ip"] = ip.to_s
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
#Put Vagrantfile in pwd
|
|
133
|
+
save_path = Pathname.new("Vagrantfile").expand_path(@env.cwd)
|
|
134
|
+
|
|
135
|
+
#Error out if Vagrantfile already exists
|
|
136
|
+
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
|
137
|
+
|
|
138
|
+
#Get current directory, go up one directory, then append path to templates/cloudbox.erb
|
|
139
|
+
template_path = File.join(File.expand_path("..",File.dirname(__FILE__)) , ("templates/multiinit.erb"))
|
|
140
|
+
|
|
141
|
+
#Load template file and write contents
|
|
142
|
+
eruby = Erubis::Eruby.new(File.read(template_path))
|
|
143
|
+
begin
|
|
144
|
+
save_path.open("w+") do |f|
|
|
145
|
+
f.write(eruby.evaluate(content))
|
|
146
|
+
end
|
|
147
|
+
rescue Errno::EACCES
|
|
148
|
+
raise Vagrant::Errors::VagrantfileWriteError
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module CommandVagrantFlow
|
|
5
|
+
module Command
|
|
6
|
+
class Root < Vagrant.plugin("2", :command)
|
|
7
|
+
def self.synopsis
|
|
8
|
+
"manages vagrantflow"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(argv, env)
|
|
12
|
+
super
|
|
13
|
+
|
|
14
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
|
15
|
+
|
|
16
|
+
@subcommands = Vagrant::Registry.new
|
|
17
|
+
@subcommands.register(:ansibleinventory) do
|
|
18
|
+
require_relative "ansibleinventory"
|
|
19
|
+
AnsibleInventory
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@subcommands.register(:multiinit) do
|
|
23
|
+
require_relative "multiinit"
|
|
24
|
+
MultiInit
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def execute
|
|
30
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
|
31
|
+
# Print the help for all the sub-commands.
|
|
32
|
+
return help
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# If we reached this far then we must have a subcommand. If not,
|
|
36
|
+
# then we also just print the help and exit.
|
|
37
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
|
38
|
+
return help if !command_class || !@sub_command
|
|
39
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
|
40
|
+
|
|
41
|
+
# Initialize and execute the command class
|
|
42
|
+
command_class.new(@sub_args, @env).execute
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Prints the help out for this command
|
|
46
|
+
def help
|
|
47
|
+
opts = OptionParser.new do |o|
|
|
48
|
+
o.banner = "Usage: vagrant flow <command> [<args>]"
|
|
49
|
+
o.separator ""
|
|
50
|
+
o.separator "Available subcommands: ansibleinventory,"
|
|
51
|
+
|
|
52
|
+
# Add the available subcommands as separators in order to print them
|
|
53
|
+
# out as well.
|
|
54
|
+
keys = []
|
|
55
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
|
56
|
+
|
|
57
|
+
keys.sort.each do |key|
|
|
58
|
+
o.separator " #{key}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
o.separator ""
|
|
62
|
+
o.separator "For help on any individual command run `vagrant flow COMMAND -h`"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@env.ui.info(opts.help, :prefix => false)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/vagrant-flow/plugin.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
require "vagrant"
|
|
2
|
+
|
|
1
3
|
module VagrantPlugins
|
|
2
|
-
module
|
|
4
|
+
module CommandVagrantFlow
|
|
3
5
|
class Plugin < Vagrant.plugin(2)
|
|
4
6
|
|
|
5
7
|
name 'vagrant-flow'
|
|
@@ -10,11 +12,17 @@ module VagrantPlugins
|
|
|
10
12
|
# Config
|
|
11
13
|
# end
|
|
12
14
|
|
|
13
|
-
command("ansible-inventory") do
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
#command("ansible-inventory") do
|
|
16
|
+
# require_relative 'command'
|
|
17
|
+
# Command
|
|
18
|
+
#end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
command("flow") do
|
|
22
|
+
require File.expand_path("../command/root.rb", __FILE__)
|
|
23
|
+
Command::Root
|
|
16
24
|
end
|
|
17
|
-
|
|
25
|
+
|
|
18
26
|
end # Plugin
|
|
19
27
|
end # Exec
|
|
20
28
|
end # VagrantPlugins
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- mode: ruby -*-
|
|
2
|
+
# vi: set ft=ruby :
|
|
3
|
+
|
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
|
6
|
+
|
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
8
|
+
|
|
9
|
+
Vagrant.require_version ">= 1.4.3"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
<% for machine in @machines %>
|
|
14
|
+
|
|
15
|
+
config.vm.define :<%= machine["name"]%> do | <%= machine["name"]%> |
|
|
16
|
+
<%= machine["name"]%>.vm.box = "<%= machine["url"]%>"
|
|
17
|
+
|
|
18
|
+
# Create a private network
|
|
19
|
+
<%= machine["name"]%>.vm.network :private_network, ip: "<%= machine["ip"]%>", virtualbox__intnet: "<%= @intnetName %>"
|
|
20
|
+
<%= machine["name"]%>.vm.hostname = "<%= machine["name"]%>"
|
|
21
|
+
|
|
22
|
+
config.vm.provider :virtualbox do |vb|
|
|
23
|
+
vb.name = "<%= machine["name"]%>"
|
|
24
|
+
# vb.customize ["modifyvm", :id, "--memory", "1024"]
|
|
25
|
+
# vb.customize ["modifyvm", :id, "--cpus", "2"]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
<% end %>
|
|
29
|
+
end
|
data/lib/vagrant-flow/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vagrant-flow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Morin
|
|
@@ -51,9 +51,13 @@ files:
|
|
|
51
51
|
- README.md
|
|
52
52
|
- Rakefile
|
|
53
53
|
- create_sample_ansible-inventory_input-file.rb
|
|
54
|
+
- create_sample_multiinit_input-file.rb
|
|
54
55
|
- lib/vagrant-flow.rb
|
|
55
|
-
- lib/vagrant-flow/command.rb
|
|
56
|
+
- lib/vagrant-flow/command/ansibleinventory.rb
|
|
57
|
+
- lib/vagrant-flow/command/multiinit.rb
|
|
58
|
+
- lib/vagrant-flow/command/root.rb
|
|
56
59
|
- lib/vagrant-flow/plugin.rb
|
|
60
|
+
- lib/vagrant-flow/templates/multiinit.erb
|
|
57
61
|
- lib/vagrant-flow/version.rb
|
|
58
62
|
- vagrant-flow.gemspec
|
|
59
63
|
homepage: http://github.com/DemandCube/vagrant-flow
|
data/lib/vagrant-flow/command.rb
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
|
-
require "vagrant"
|
|
3
|
-
require "yaml"
|
|
4
|
-
|
|
5
|
-
module VagrantPlugins
|
|
6
|
-
module VagrantFlow
|
|
7
|
-
class Command < Vagrant.plugin("2", :command)
|
|
8
|
-
|
|
9
|
-
# Builtin from Command class
|
|
10
|
-
# Must override to provide a description
|
|
11
|
-
def self.synopsis
|
|
12
|
-
"generates a ansible inventory file from the vagrant environment"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# Builtin from Command class
|
|
17
|
-
# Must override to provide core functionality
|
|
18
|
-
def execute
|
|
19
|
-
|
|
20
|
-
machines_configs = {}
|
|
21
|
-
inventory_configs = {}
|
|
22
|
-
|
|
23
|
-
default_group_config_file = "groupconfig.yml"
|
|
24
|
-
options = {}
|
|
25
|
-
options[:destroy_on_error] = true
|
|
26
|
-
options[:parallel] = false
|
|
27
|
-
options[:provision_ignore_sentinel] = false
|
|
28
|
-
options[:quiet] = false
|
|
29
|
-
|
|
30
|
-
#Setting to read in a file other than default_group_config_File
|
|
31
|
-
options[:custom_config_file] = false
|
|
32
|
-
#Setting to parse the VAGRANTFILE's ansible group config
|
|
33
|
-
options[:vagrantFileAnsibleConfig] = false
|
|
34
|
-
|
|
35
|
-
#Parse option, look up OptionParser documentation
|
|
36
|
-
opts = OptionParser.new do |o|
|
|
37
|
-
# o.banner = "Usage: vagrant ansible-inventory [vm-name] [options] [-h]"
|
|
38
|
-
o.banner = "A NeverWinterDP technology from the Department of Badass.\n\n"+
|
|
39
|
-
"Usage: vagrant ansible-inventory [-hgpq]\nThis looks for groupconfig.yml as the default configuration\n"+
|
|
40
|
-
"Do not use -p and -g options together!"
|
|
41
|
-
o.separator ""
|
|
42
|
-
o.on("-g", "--group_config_file FILEPATH", "(Optional) YAML file containing group config") do |f|
|
|
43
|
-
options[:custom_config_file] = f
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
o.on("-p", "--vagrantfileparse", "(Optional) Read in the VAGRANTFILE's ansible group config") do |f|
|
|
47
|
-
options[:vagrantFileAnsibleConfig] = true
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
o.on("-q", "--quiet", "(Optional) Suppress output to STDOUT and STDERR") do |f|
|
|
51
|
-
options[:quiet] = true
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Parse the options # Builtin from the Command Class
|
|
57
|
-
# Will safely parse the arguments and
|
|
58
|
-
# Automatically detects -h for help
|
|
59
|
-
argv = parse_options(opts)
|
|
60
|
-
return if !argv
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# The following are already setup by the parent class
|
|
65
|
-
# @env
|
|
66
|
-
# @logger
|
|
67
|
-
# @argv
|
|
68
|
-
|
|
69
|
-
# Go over each VM and bring it up
|
|
70
|
-
@logger.debug("'ansible-inventory' created for the whole env")
|
|
71
|
-
|
|
72
|
-
#Initialize group_machines, the has containing group=>machinename configs
|
|
73
|
-
group_machines={}
|
|
74
|
-
|
|
75
|
-
#Get info about the vagrant boxes
|
|
76
|
-
with_target_vms(argv, :provider => options[:provider]) do |machine|
|
|
77
|
-
# @env.ui
|
|
78
|
-
# output methods: :ask, :detail, :warn, :error, :info, :output, :success
|
|
79
|
-
# https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb
|
|
80
|
-
|
|
81
|
-
ssh_info = machine.ssh_info
|
|
82
|
-
raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
|
|
83
|
-
|
|
84
|
-
variables = {
|
|
85
|
-
:host_key => options[:host] || machine.name || "vagrant",
|
|
86
|
-
:ssh_host => ssh_info[:host],
|
|
87
|
-
:ssh_port => ssh_info[:port],
|
|
88
|
-
:ssh_user => ssh_info[:username],
|
|
89
|
-
:private_key_path => ssh_info[:private_key_path],
|
|
90
|
-
:forward_agent => ssh_info[:forward_agent],
|
|
91
|
-
:forward_x11 => ssh_info[:forward_x11]
|
|
92
|
-
}
|
|
93
|
-
# Outputs to the stdout
|
|
94
|
-
|
|
95
|
-
inventory_configs = {
|
|
96
|
-
:vagrant_file_dir => machine.env.root_path,
|
|
97
|
-
:vagrant_flow_file => machine.env.root_path.join("vagrant-flow_ansible_inventory")
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
machines_configs[variables[:host_key]]= variables
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
#Hash containing group/machine configuration
|
|
104
|
-
group_machines={}
|
|
105
|
-
#Determine group_machines based on what config options are passed in
|
|
106
|
-
#Read in config from vagrantfile's ansible config
|
|
107
|
-
if options[:vagrantFileAnsibleConfig] == true
|
|
108
|
-
provisioners = []
|
|
109
|
-
with_target_vms(argv, :provider => options[:provider]) do |machine|
|
|
110
|
-
#The provisioning information from teh vagrant file, this will contain our defined ansible groups
|
|
111
|
-
#Concatenate all the provisioner configs together
|
|
112
|
-
if machine.config.vm.provisioners
|
|
113
|
-
provisioners.concat(machine.config.vm.provisioners)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
#Since Vagrant machines will likely contain the same configs,
|
|
117
|
-
#Merge the config together to remove duplicate entries in our
|
|
118
|
-
#group/machine configuration
|
|
119
|
-
provisioners.each {|prov|
|
|
120
|
-
group_machines = group_machines.merge(prov.config.groups)
|
|
121
|
-
}
|
|
122
|
-
#Read in config from yaml file
|
|
123
|
-
else
|
|
124
|
-
#Use config option if specified
|
|
125
|
-
if options[:custom_config_file] != false
|
|
126
|
-
default_group_config_file = options[:custom_config_file]
|
|
127
|
-
end
|
|
128
|
-
begin
|
|
129
|
-
#Load YAML
|
|
130
|
-
group_machines = YAML.load_file(default_group_config_file)
|
|
131
|
-
rescue
|
|
132
|
-
#Give warning if no file could be found
|
|
133
|
-
if not options[:quiet]
|
|
134
|
-
warn "Could not open file: "+default_group_config_file.to_s
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
# Outputs to the stdout
|
|
142
|
-
# @env.ui.info(machine.name)
|
|
143
|
-
|
|
144
|
-
# From - Vagrant::Util::SafePuts
|
|
145
|
-
# Template is erb
|
|
146
|
-
|
|
147
|
-
# Implementation picks the first key
|
|
148
|
-
# ssh_info[:private_key_path] returns an array
|
|
149
|
-
|
|
150
|
-
#outputs is going to contain our strings that are the formatted ansible configs
|
|
151
|
-
#the key will be the vm name, the value will the be formatted sring
|
|
152
|
-
outputs = {}
|
|
153
|
-
|
|
154
|
-
inventory_configs[:vagrant_flow_file].open('w') do |file|
|
|
155
|
-
machines_configs.each do |host, variables|
|
|
156
|
-
ansible_template = '<%= host_key %> ansible_ssh_host=<%= ssh_host %> ansible_ssh_port=<%= ssh_port %> ansible_ssh_user=<%= ssh_user %> ansible_ssh_private_key_file=<%= private_key_path[0] %> # Machine Name: <%= host_key %>'
|
|
157
|
-
outputs[variables[:host_key]] = Vagrant::Util::TemplateRenderer.render_string(ansible_template, variables)
|
|
158
|
-
#safe_puts(host_txt)
|
|
159
|
-
#file.write("#{host_txt}\n")
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
#require 'pp'
|
|
164
|
-
#puts "PROVISIONERS"
|
|
165
|
-
#PP.pp(provisioners)
|
|
166
|
-
#puts "OUTPUTS"
|
|
167
|
-
#PP.pp(outputs)
|
|
168
|
-
#puts "\n\n"
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
inventory_configs[:vagrant_flow_file].open('w') do |file|
|
|
173
|
-
header_txt="# Generated by vagrant-flow, part of NeverwinterDP\n\n"
|
|
174
|
-
if not options[:quiet]
|
|
175
|
-
safe_puts(header_txt)
|
|
176
|
-
end
|
|
177
|
-
file.write(header_txt)
|
|
178
|
-
|
|
179
|
-
#Now we maps from our VAGRANTFILE defined groups in our provisioners.config.groups
|
|
180
|
-
#To our configuration strings we got from outputs
|
|
181
|
-
group_machines.each do |groupname,machines|
|
|
182
|
-
if not options[:quiet]
|
|
183
|
-
puts "["+groupname+"]\n"
|
|
184
|
-
end
|
|
185
|
-
file.write "["+groupname+"]\n"
|
|
186
|
-
machines.each do |machinename|
|
|
187
|
-
#if we match :children, then we have an ansible config that's
|
|
188
|
-
#pointing to another group, not a specific machine
|
|
189
|
-
if /:children/.match(groupname)
|
|
190
|
-
if not options[:quiet]
|
|
191
|
-
puts machinename
|
|
192
|
-
end
|
|
193
|
-
file.write machinename+"\n"
|
|
194
|
-
else
|
|
195
|
-
if not options[:quiet]
|
|
196
|
-
puts outputs[machinename.to_sym]+"\n"
|
|
197
|
-
end
|
|
198
|
-
file.write outputs[machinename.to_sym]+"\n"
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
if not options[:quiet]
|
|
202
|
-
puts "\n"
|
|
203
|
-
end
|
|
204
|
-
file.write "\n"
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
0
|
|
208
|
-
end # End Execute
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
# Documentation reference
|
|
212
|
-
# http://docs.ansible.com/intro_inventory.html
|
|
213
|
-
|
|
214
|
-
def setup_inventory_file(machine)
|
|
215
|
-
return machine.config.inventory_path if machine.config.inventory_path
|
|
216
|
-
|
|
217
|
-
ssh = machine.ssh_info
|
|
218
|
-
|
|
219
|
-
generated_inventory_file =
|
|
220
|
-
machine.env.root_path.join("vagrant-flow_ansible_inventory")
|
|
221
|
-
|
|
222
|
-
generated_inventory_file.open('w') do |file|
|
|
223
|
-
file.write("# Generated by Vagrant\n\n")
|
|
224
|
-
file.write("#{machine.name} ansible_ssh_host=#{ssh[:host]} ansible_ssh_port=#{ssh[:port]}\n")
|
|
225
|
-
|
|
226
|
-
# Write out groups information. Only include current
|
|
227
|
-
# machine and its groups to avoid Ansible errors on
|
|
228
|
-
# provisioning.
|
|
229
|
-
groups_of_groups = {}
|
|
230
|
-
included_groups = []
|
|
231
|
-
|
|
232
|
-
config.groups.each_pair do |gname, gmembers|
|
|
233
|
-
if gname.end_with?(":children")
|
|
234
|
-
groups_of_groups[gname] = gmembers
|
|
235
|
-
elsif gmembers.include?("#{machine.name}")
|
|
236
|
-
included_groups << gname
|
|
237
|
-
file.write("\n[#{gname}]\n")
|
|
238
|
-
file.write("#{machine.name}\n")
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
groups_of_groups.each_pair do |gname, gmembers|
|
|
243
|
-
unless (included_groups & gmembers).empty?
|
|
244
|
-
file.write("\n[#{gname}]\n")
|
|
245
|
-
gmembers.each do |gm|
|
|
246
|
-
file.write("#{gm}\n") if included_groups.include?(gm)
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
return generated_inventory_file.to_s
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|