lib/vagrant/compose/programmatic/cluster.rb in vagrant-compose-0.7.1 vs lib/vagrant/compose/programmatic/cluster.rb in vagrant-compose-0.7.2

- old
+ new

@@ -92,10 +92,11 @@ node.ansible_groups.each do |ansible_group| ansible_groups[ansible_group] = [] unless ansible_groups.has_key? (ansible_group) ansible_groups[ansible_group] << node end end + extended_ansible_groups = ansible_groups.merge({'all' => nodes}) ## Fase2: Configurazione provisioning del cluster via Ansible # Ogni nodo diventerà una vm su cui sarà fatto il provisioning, ovvero un host nell'inventory di ansible # Ad ogni gruppo corrispondono nodi con caratteristiche simili @@ -118,11 +119,11 @@ # definizione del cluster. context = {} #genearazione context (NB. 1 group = 1 gruppo host ansible) - ansible_groups.each do |ansible_group, ansible_group_nodes| + extended_ansible_groups.each do |ansible_group, ansible_group_nodes| # genero le variabili per il group provisioners = @ansible_context_vars[ansible_group] unless provisioners.nil? # se necessario, normalizzo provisioner in array provisioners @@ -143,15 +144,16 @@ # cleanup ansible_group_vars files # TODO: make safe ansible_group_vars_path = File.join(@ansible_playbook_path, 'group_vars') - FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path) - Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")} + if File.exists?(ansible_group_vars_path) + Dir.foreach(ansible_group_vars_path) {|f| fn = File.join(ansible_group_vars_path, f); File.delete(fn) if f.end_with?(".yml")} + end #generazione ansible_group_vars file (NB. 1 group = 1 gruppo host ansible) - ansible_groups.each do |ansible_group, ansible_group_nodes| + extended_ansible_groups.each do |ansible_group, ansible_group_nodes| ansible_group_vars = {} # genero le variabili per il group provisioners = @ansible_group_vars[ansible_group] unless provisioners.nil? # se necessario, normalizzo provisioner in array provisioners @@ -169,23 +171,27 @@ end end # crea il file (se sono state generate delle variabili) unless ansible_group_vars.empty? + FileUtils.mkdir_p(ansible_group_vars_path) unless File.exists?(ansible_group_vars_path) + # TODO: make safe - File.open(File.join(ansible_group_vars_path,"#{ansible_group}.yml") , 'w+') do |file| + fileName = ansible_group.gsub(':', '_') + File.open(File.join(ansible_group_vars_path,"#{fileName}.yml") , 'w+') do |file| file.puts YAML::dump(ansible_group_vars) end end end # cleanup ansible_host_vars files (NB. 1 nodo = 1 host) # TODO: make safe ansible_host_vars_path = File.join(@ansible_playbook_path, 'host_vars') - FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path) - Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")} + if File.exists?(ansible_host_vars_path) + Dir.foreach(ansible_host_vars_path) {|f| fn = File.join(ansible_host_vars_path, f); File.delete(fn) if f.end_with?(".yml")} + end #generazione ansible_host_vars file nodes.each do |node| # genero le variabili per il nodo; il nodo, può essere abbinato a diversi gruppi ansible_host_vars = {} @@ -209,9 +215,11 @@ end end # crea il file (se sono state generate delle variabili) unless ansible_host_vars.empty? + FileUtils.mkdir_p(ansible_host_vars_path) unless File.exists?(ansible_host_vars_path) + # TODO: make safe File.open(File.join(ansible_host_vars_path,"#{node.hostname}.yml") , 'w+') do |file| file.puts YAML::dump(ansible_host_vars) end end