vagrant-compose 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2ca4a2adb7273d09c0650fa06fc3d3f059d8e3a
4
- data.tar.gz: 95c5b8b69f87f119e51b76507cba24716902625c
3
+ metadata.gz: 4c6ecc542370d381b4e4636b64a51eb34cb90d98
4
+ data.tar.gz: f7846bf3c0d2956c29cea6faf68a767a2bb6ffe0
5
5
  SHA512:
6
- metadata.gz: f24a63d849bd0b574bed06bdcc1e454b6549f93a1ef0bd4367888541cf889f5bdf79f5e13ccfc320c9a546ce4712181428e5a5a905ba2c56a335b42753df30d8
7
- data.tar.gz: 1a682bf36be2fb2d1b6501bbae5ed7b04e29d206d7c8aa45192b584d0ecdd37f58787c2f2357d0e37826a44bd27eccc0b9503f633a5719c8a9cb217973db9496
6
+ metadata.gz: 25546d557103418fe05a94b315c98b56e09c05bfebbe1c8d3117110d82604bca6f2a9b7722fd2244156372c1fbbe975125036ba1bfe592eb5f698ff602ec8000
7
+ data.tar.gz: 62d8daf320048e2d101222d6ddb49faa0498d258d589b4ff2309fb5da4db6686dc5474487cdf89894439d993134b12b695a2a2eaa997d28580d52faf9ddb1425
data/CHANGELOG.md CHANGED
@@ -40,3 +40,9 @@ ansible_group_vars_path and ansible_host_vars_path are not supported anymore
40
40
 
41
41
  * Minor fix
42
42
 
43
+ # 0.7.2 (November 16, 2016)
44
+
45
+ * issues #11 Allow management of Ansible vars for all hosts
46
+ * issues #9 Create group_vars and host_vars directory only if necessary
47
+
48
+ * breacking change: custom group of groups all_groups:children removed. Insteal use all (automatically created by ansible)
data/doc/declarative.md CHANGED
@@ -295,9 +295,9 @@ kubernetes:
295
295
  ...
296
296
  ...
297
297
  ansible_group_vars:
298
- etcd :
298
+ etcd:
299
299
  var1: ...
300
- docker :
300
+ docker:
301
301
  var2: ...
302
302
  var3: ...
303
303
  ...
@@ -308,6 +308,17 @@ Group vars can be set to literal value or to Jinja2 value generators, that will
308
308
  - **context_vars** see below
309
309
  - **nodes**, list of nodes in the ansible_group to which the group_vars belong
310
310
 
311
+ Additionally it is possible to set variables for all groups/all hosts, by setting vars for the pre-defined `all` group of groups:
312
+
313
+ ```yaml
314
+ kubernetes:
315
+ ...
316
+ ansible_group_vars:
317
+ all:
318
+ var1: ...
319
+ ...
320
+ ```
321
+
311
322
  Ansible group vars will be stored into yaml files saved into `{cluster.ansible_playbook_path}\group_vars` folder.
312
323
 
313
324
  The variable `cluster.ansible_playbook_path` defaults to the current directory (the directory of the Vagrantfile) + `/provisioning`; this value can be changed like any other cluster attributes (see Defining cluster & cluster attributes).
@@ -384,18 +395,42 @@ Context vars can be set to literal value or to Jinja2 value generators, that wil
384
395
 
385
396
  - nodes, list of nodes in the ansible_group to which the group_vars belong
386
397
 
387
-
388
398
  > Context_vars generator are always executed before group_vars and host_vars generators; the resulting context, is given in input to group_vars and host_vars generators.
389
399
 
400
+ > In addition to context vars for groups, it is possible to create context_vars for all groups/all hosts, by setting vars for the pre-defined `all` group of groups; in this case, intuitively, the list of nodes whitin the context contains all the nodes.
401
+
390
402
  Then, you can use the above context var when generating group_vars for host vars.
391
403
 
404
+ ```yaml
405
+ kubernetes:
406
+ box: centos/7
407
+ master:
408
+ ...
409
+ ansible_groups:
410
+ - kb8-master
411
+ minions:
412
+ ...
413
+ ansible_groups:
414
+ - kb8-minions
415
+
416
+ ansible_context_vars:
417
+ all:
418
+ var0: "{{ nodes | count }}"
419
+ kb8-master:
420
+ var1: "{{ nodes | count }}"
421
+
422
+ ansible_group_vars:
423
+ all:
424
+ var0_from_context: "{{ context['var0'] }}"
425
+ kb8-master:
426
+ var1_from_context: "{{ context['var1'] }}"
427
+ ```
428
+
392
429
  ### Group of groups
393
430
 
394
431
  A useful ansible inventory feature is [group of groups](http://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups).
395
432
 
396
- By default vagrant-compose will generate a group named `[all_groups:children]` with all the ansible_groups defined in cluster configuration; however:
397
- - you cannot rename all_groups
398
- - you cannot exclude any ansible group from all_groups.
433
+ By default ansible has a group named `[all]` with all nodes in the cluster.
399
434
 
400
435
  If you need higher control on groups of groups you can simply add a new item to the variable `config.cluster.ansible_groups` before creating nodes.
401
436
 
data/doc/programmatic.md CHANGED
@@ -302,9 +302,9 @@ end
302
302
 
303
303
  As you can see, `consul` and `docker` ansible_groups now include both nodes from `consul-agent` and `load-balancer` node set; vice versa, other groups like `registrator`, `consul-template`, `nginx` contain node only from one of the two nodes set.
304
304
 
305
- Ansible playbook can leverage on groups for providing machines with the required software stacks.
305
+ Ansible playbook can additionally leverage on groups for providing machines with the required software stacks.
306
306
 
307
- NB. you can see resulting ansible_groups by using `debug` command with `verbose` equal to `true`.
307
+ > NB. you can see resulting ansible_groups by using `debug` command with `verbose` equal to `true`.
308
308
 
309
309
  ### Defining group vars
310
310
 
@@ -329,6 +329,18 @@ config.cluster.compose('test') do |c|
329
329
  end
330
330
  ```
331
331
 
332
+ Additionally, it is possible to set variables for all groups/all hosts, by setting vars for the pre-defined `all` group of groups:
333
+
334
+ ``` ruby
335
+ config.cluster.compose('test') do |c|
336
+ ...
337
+ c.ansible_group_vars['all'] = lambda { |context, nodes|
338
+ return { 'var0' => nodes.length }
339
+ }
340
+ ...
341
+ end
342
+ ```
343
+
332
344
  Ansible group vars will be stored into yaml files saved into `{cluster.ansible_playbook_path}\group_vars` folder.
333
345
 
334
346
  The variable `cluster.ansible_playbook_path` defaults to the current directory (the directory of the Vagrantfile) + `/provisioning`; this value can be changed like any other cluster attributes (see Defining cluster attributes).
@@ -379,6 +391,8 @@ end
379
391
 
380
392
  > Context_vars generator are always executed before group_vars and host_vars generators; the resulting context, is given in input to group_vars and host_vars generators.
381
393
 
394
+ > In addition to context vars for groups, it is possible to create context_vars for all groups/all hosts, by setting vars for the pre-defined `all` group of groups; in this case, intuitively, the list of nodes whitin the context contains all the nodes.
395
+
382
396
  Then, you can use the above context var when generating group_vars for nodes in the `consul-agent` group.
383
397
 
384
398
  ``` ruby
@@ -397,9 +411,7 @@ end
397
411
  ### Group of groups
398
412
  A useful ansible inventory feature is [group of groups](http://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups).
399
413
 
400
- By default vagrant-compose will generate a group named `[all_groups:children]` with all the ansible_groups defined in cluster configuration; however:
401
- - you cannot rename all_groups
402
- - you cannot exclude any ansible group from all_groups.
414
+ By default ansible has a group named `[all]` with all the nodes defined in cluster configuration.
403
415
 
404
416
  If you need higher control on groups of groups you can simply add a new item to the variable `config.cluster.ansible_groups` before creating nodes.
405
417
 
@@ -62,8 +62,6 @@ module VagrantPlugins
62
62
  end
63
63
  end
64
64
 
65
- ansible_groups['all_groups:children'] = ansible_groups.keys
66
-
67
65
  return ansible_groups
68
66
  end
69
67
 
@@ -74,16 +74,19 @@ module VagrantPlugins
74
74
  # TODO: make safe
75
75
  ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars')
76
76
 
77
- FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path)
78
- Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
77
+ if File.exists?(ansible_group_vars_path)
78
+ Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
79
+ end
79
80
 
80
81
  #generazione ansible_group_vars file (NB. 1 group = 1 gruppo host ansible)
81
82
  if ansible.key?("group_vars")
82
83
  ansible['group_vars'].each do |group, vars|
83
84
  # crea il file (se sono state generate delle variabili)
84
85
  unless vars.empty?
86
+ FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path)
85
87
  # TODO: make safe
86
- File.open(File.join(ansible_group_vars_path,"#{group}.yml") , 'w+') do |file|
88
+ fileName = group.gsub(':', '_')
89
+ File.open(File.join(ansible_group_vars_path,"#{fileName}.yml") , 'w+') do |file|
87
90
  file.puts YAML::dump(vars)
88
91
  end
89
92
  end
@@ -94,14 +97,17 @@ module VagrantPlugins
94
97
  # TODO: make safe
95
98
  ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars')
96
99
 
97
- FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path)
98
- Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
100
+ if File.exists?(ansible_host_vars_path)
101
+ Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
102
+ end
99
103
 
100
104
  #generazione ansible_host_vars file
101
105
  if ansible.key?("host_vars")
102
106
  ansible['host_vars'].each do |host, vars|
103
107
  # crea il file (se sono state generate delle variabili)
104
108
  unless vars.empty?
109
+ FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path)
110
+
105
111
  # TODO: make safe
106
112
  File.open(File.join(ansible_host_vars_path,"#{host}.yml") , 'w+') do |file|
107
113
  file.puts YAML::dump(vars)
@@ -94,6 +94,7 @@ module VagrantPlugins
94
94
  ansible_groups[ansible_group] << node
95
95
  end
96
96
  end
97
+ extended_ansible_groups = ansible_groups.merge({'all' => nodes})
97
98
 
98
99
  ## Fase2: Configurazione provisioning del cluster via Ansible
99
100
  # Ogni nodo diventerà una vm su cui sarà fatto il provisioning, ovvero un host nell'inventory di ansible
@@ -120,7 +121,7 @@ module VagrantPlugins
120
121
  context = {}
121
122
 
122
123
  #genearazione context (NB. 1 group = 1 gruppo host ansible)
123
- ansible_groups.each do |ansible_group, ansible_group_nodes|
124
+ extended_ansible_groups.each do |ansible_group, ansible_group_nodes|
124
125
  # genero le variabili per il group
125
126
  provisioners = @ansible_context_vars[ansible_group]
126
127
  unless provisioners.nil?
@@ -145,11 +146,12 @@ module VagrantPlugins
145
146
  # TODO: make safe
146
147
  ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars')
147
148
 
148
- FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path)
149
- Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
149
+ if File.exists?(ansible_group_vars_path)
150
+ Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
151
+ end
150
152
 
151
153
  #generazione ansible_group_vars file (NB. 1 group = 1 gruppo host ansible)
152
- ansible_groups.each do |ansible_group, ansible_group_nodes|
154
+ extended_ansible_groups.each do |ansible_group, ansible_group_nodes|
153
155
  ansible_group_vars = {}
154
156
  # genero le variabili per il group
155
157
  provisioners = @ansible_group_vars[ansible_group]
@@ -171,8 +173,11 @@ module VagrantPlugins
171
173
 
172
174
  # crea il file (se sono state generate delle variabili)
173
175
  unless ansible_group_vars.empty?
176
+ FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path)
177
+
174
178
  # TODO: make safe
175
- File.open(File.join(ansible_group_vars_path,"#{ansible_group}.yml") , 'w+') do |file|
179
+ fileName = ansible_group.gsub(':', '_')
180
+ File.open(File.join(ansible_group_vars_path,"#{fileName}.yml") , 'w+') do |file|
176
181
  file.puts YAML::dump(ansible_group_vars)
177
182
  end
178
183
  end
@@ -182,8 +187,9 @@ module VagrantPlugins
182
187
  # TODO: make safe
183
188
  ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars')
184
189
 
185
- FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path)
186
- Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
190
+ if File.exists?(ansible_host_vars_path)
191
+ Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")}
192
+ end
187
193
 
188
194
  #generazione ansible_host_vars file
189
195
  nodes.each do |node|
@@ -211,6 +217,8 @@ module VagrantPlugins
211
217
 
212
218
  # crea il file (se sono state generate delle variabili)
213
219
  unless ansible_host_vars.empty?
220
+ FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path)
221
+
214
222
  # TODO: make safe
215
223
  File.open(File.join(ansible_host_vars_path,"#{node.hostname}.yml") , 'w+') do |file|
216
224
  file.puts YAML::dump(ansible_host_vars)
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Compose
3
- VERSION = "0.7.1"
3
+ VERSION = "0.7.2"
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ var0_bis: '2'
@@ -0,0 +1,2 @@
1
+ ---
2
+ var1_bis: '1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Pandini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,6 +92,8 @@ files:
92
92
  - lib/vagrant/compose/version.rb
93
93
  - lib/vagrant/compose.rb
94
94
  - LICENCE
95
+ - provisioning/group_vars/all.yml
96
+ - provisioning/group_vars/kb8-master.yml
95
97
  - Rakefile
96
98
  - README.md
97
99
  - vagrant-compose.gemspec