vagrant-flow 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -4
- data/create_sample_ansible-inventory_input-file.rb +26 -0
- data/lib/vagrant-flow/command.rb +91 -34
- data/lib/vagrant-flow/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 987d348d2383b329ac2e6d646ffb9a84da357da2
|
4
|
+
data.tar.gz: 11aaca9f68aa6db12f372e3eb92c29c1c8fd6395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c335c7777a4c0f1684b3dbda635c78b14877aa679754d2fffdc2a672c9f9285d57611ea019090597165ff0cbc136e4e15d8c8d75e5893700a3009d064170aa5
|
7
|
+
data.tar.gz: 21e55b67a680606edccfbe4cb57e7dbf8735eac405117de095fadeae97f0e46b443c3f7522e7955b7dda7db11d63ac7a4bbb58452760b691d18b39e79cd3269e
|
data/README.md
CHANGED
@@ -24,18 +24,66 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
```
|
27
|
+
Usage: vagrant ansible-inventory [-hgpq]
|
28
|
+
This plugin looks for groupconfig.yml as the default configuration
|
29
|
+
Do not use -p and -g options together!
|
30
|
+
|
31
|
+
-g, --group_config_file FILEPATH (Optional) YAML file containing group config
|
32
|
+
-p, --vagrantfileparse (Optional) Read in the VAGRANTFILE's ansible group config
|
33
|
+
-q, --quiet (Optional) Suppress output to STDOUT and STDERR
|
34
|
+
-h, --help (Optional) Print this help
|
35
|
+
```
|
36
|
+
|
37
|
+
## Example usages
|
38
|
+
This will look for a file in the pwd named groupconfig.yml and attempt to make the inventory
|
39
|
+
```
|
40
|
+
vagrant ansible-inventory
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
This will look for a file in the pwd named myOwnGroupConfig.yml and attempt to make the inventory
|
46
|
+
```
|
47
|
+
vagrant ansible-inventory -g myOwnGroupConfig.yml
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
This will parse the vagrant file for ansible group configs
|
53
|
+
```
|
54
|
+
vagrant ansible-inventory -p
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
## Use case
|
62
|
+
```
|
27
63
|
#Bring up your vagrant machines
|
28
64
|
vagrant up
|
29
|
-
#Run ansible inventory
|
65
|
+
#Run ansible inventory (this assumes the file groupconfig.yml exists)
|
30
66
|
vagrant ansible-inventory
|
31
67
|
#point ansible-playbook to the generated vagrant-flow_ansible_inventory, and point them to whatever playbook you'd like
|
32
68
|
ansible-playbook -i path/to/vagrant-flow_ansible_inventory my_playbook.yml
|
33
69
|
```
|
34
70
|
## Usage Expectations
|
71
|
+
#### Don't mix the -p and -g options. Unexpected things will happen.
|
35
72
|
|
36
|
-
|
73
|
+
Example groupconfig.yml file (for use with no optional command line arguments or by pointing to non-default file with -g option)
|
74
|
+
```
|
75
|
+
---
|
76
|
+
common:children:
|
77
|
+
- testgroup
|
78
|
+
- servergroup
|
79
|
+
testgroup:
|
80
|
+
- testbox
|
81
|
+
servergroup:
|
82
|
+
- server1
|
83
|
+
- server2
|
84
|
+
```
|
37
85
|
|
38
|
-
Example VAGRANTFILE excerpt:
|
86
|
+
Example VAGRANTFILE excerpt (for use with -p option):
|
39
87
|
```
|
40
88
|
config.vm.provision "ansible" do |ansible|
|
41
89
|
#ansible.playbook is required, but emptyplaybook.yml can do nothing,
|
@@ -49,7 +97,7 @@ config.vm.provision "ansible" do |ansible|
|
|
49
97
|
end
|
50
98
|
```
|
51
99
|
|
52
|
-
Example playbook.yml
|
100
|
+
Example playbook.yml to use after ansible-inventory has run with command `ansible-playbook -i vagrant-flow_ansible_inventory playbook.yml`:
|
53
101
|
```
|
54
102
|
---
|
55
103
|
#Configures the groups defined in common:children
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|
7
|
+
x = {
|
8
|
+
"common:children"=>["jenkins","server"],
|
9
|
+
"jenkins"=>["jenkinsdp"],
|
10
|
+
"server"=>["sparkngin1","sparkngin2"],
|
11
|
+
}
|
12
|
+
|
13
|
+
begin
|
14
|
+
File.open('groupconfig.yml', 'w') {|f| f.write x.to_yaml }
|
15
|
+
rescue
|
16
|
+
warn "Could not write file groupconfig.yml"
|
17
|
+
end
|
18
|
+
|
19
|
+
y = YAML.load(x.to_yaml)
|
20
|
+
|
21
|
+
y.each {|key,value|
|
22
|
+
puts key
|
23
|
+
puts value
|
24
|
+
puts "\n"
|
25
|
+
}
|
26
|
+
|
data/lib/vagrant-flow/command.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
require "vagrant"
|
3
|
+
require "yaml"
|
3
4
|
|
4
5
|
module VagrantPlugins
|
5
6
|
module VagrantFlow
|
@@ -19,28 +20,37 @@ module VagrantPlugins
|
|
19
20
|
machines_configs = {}
|
20
21
|
inventory_configs = {}
|
21
22
|
|
23
|
+
default_group_config_file = "groupconfig.yml"
|
22
24
|
options = {}
|
23
25
|
options[:destroy_on_error] = true
|
24
26
|
options[:parallel] = false
|
25
27
|
options[:provision_ignore_sentinel] = false
|
26
|
-
|
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
|
27
36
|
opts = OptionParser.new do |o|
|
28
37
|
# o.banner = "Usage: vagrant ansible-inventory [vm-name] [options] [-h]"
|
29
|
-
o.banner = "
|
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!"
|
30
41
|
o.separator ""
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
53
|
|
38
|
-
# This option isn't used.
|
39
|
-
#o.on("--[no-]parallel",
|
40
|
-
# "Enable or disable parallelism if provider supports it.") do |parallel|
|
41
|
-
# options[:parallel] = parallel
|
42
|
-
#end
|
43
|
-
|
44
54
|
end
|
45
55
|
|
46
56
|
# Parse the options # Builtin from the Command Class
|
@@ -48,6 +58,8 @@ module VagrantPlugins
|
|
48
58
|
# Automatically detects -h for help
|
49
59
|
argv = parse_options(opts)
|
50
60
|
return if !argv
|
61
|
+
|
62
|
+
|
51
63
|
|
52
64
|
# The following are already setup by the parent class
|
53
65
|
# @env
|
@@ -56,10 +68,11 @@ module VagrantPlugins
|
|
56
68
|
|
57
69
|
# Go over each VM and bring it up
|
58
70
|
@logger.debug("'ansible-inventory' created for the whole env")
|
59
|
-
|
60
71
|
|
72
|
+
#Initialize group_machines, the has containing group=>machinename configs
|
73
|
+
group_machines={}
|
61
74
|
|
62
|
-
|
75
|
+
#Get info about the vagrant boxes
|
63
76
|
with_target_vms(argv, :provider => options[:provider]) do |machine|
|
64
77
|
# @env.ui
|
65
78
|
# output methods: :ask, :detail, :warn, :error, :info, :output, :success
|
@@ -79,9 +92,6 @@ module VagrantPlugins
|
|
79
92
|
}
|
80
93
|
# Outputs to the stdout
|
81
94
|
|
82
|
-
#The provisioning information from teh vagrant file, this will contain our defined ansible groups
|
83
|
-
provisioners = machine.config.vm.provisioners
|
84
|
-
|
85
95
|
inventory_configs = {
|
86
96
|
:vagrant_file_dir => machine.env.root_path,
|
87
97
|
:vagrant_flow_file => machine.env.root_path.join("vagrant-flow_ansible_inventory")
|
@@ -90,6 +100,43 @@ module VagrantPlugins
|
|
90
100
|
machines_configs[variables[:host_key]]= variables
|
91
101
|
end
|
92
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
|
+
|
93
140
|
|
94
141
|
# Outputs to the stdout
|
95
142
|
# @env.ui.info(machine.name)
|
@@ -120,33 +167,43 @@ module VagrantPlugins
|
|
120
167
|
#PP.pp(outputs)
|
121
168
|
#puts "\n\n"
|
122
169
|
|
170
|
+
|
171
|
+
|
123
172
|
inventory_configs[:vagrant_flow_file].open('w') do |file|
|
124
173
|
header_txt="# Generated by vagrant-flow, part of NeverwinterDP\n\n"
|
125
|
-
|
174
|
+
if not options[:quiet]
|
175
|
+
safe_puts(header_txt)
|
176
|
+
end
|
126
177
|
file.write(header_txt)
|
127
178
|
|
128
179
|
#Now we maps from our VAGRANTFILE defined groups in our provisioners.config.groups
|
129
180
|
#To our configuration strings we got from outputs
|
130
|
-
|
131
|
-
|
181
|
+
group_machines.each do |groupname,machines|
|
182
|
+
if not options[:quiet]
|
132
183
|
puts "["+groupname+"]\n"
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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]
|
138
191
|
puts machinename
|
139
|
-
|
140
|
-
|
192
|
+
end
|
193
|
+
file.write machinename+"\n"
|
194
|
+
else
|
195
|
+
if not options[:quiet]
|
141
196
|
puts outputs[machinename.to_sym]+"\n"
|
142
|
-
file.write outputs[machinename.to_sym]+"\n"
|
143
197
|
end
|
198
|
+
file.write outputs[machinename.to_sym]+"\n"
|
144
199
|
end
|
200
|
+
end
|
201
|
+
if not options[:quiet]
|
145
202
|
puts "\n"
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
203
|
+
end
|
204
|
+
file.write "\n"
|
205
|
+
end
|
206
|
+
end
|
150
207
|
0
|
151
208
|
end # End Execute
|
152
209
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Morin
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- NEVERWINTERDP
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
+
- create_sample_ansible-inventory_input-file.rb
|
53
54
|
- lib/vagrant-flow.rb
|
54
55
|
- lib/vagrant-flow/command.rb
|
55
56
|
- lib/vagrant-flow/plugin.rb
|