]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
auto compile before deploy (as needed)
authorelijah <elijah@riseup.net>
Thu, 13 Dec 2012 06:40:59 +0000 (22:40 -0800)
committerelijah <elijah@riseup.net>
Thu, 13 Dec 2012 06:40:59 +0000 (22:40 -0800)
lib/leap_cli/commands/compile.rb
lib/leap_cli/commands/deploy.rb
lib/leap_cli/config/manager.rb

index 45e4f2b3d0f7dceb11616f615b834ed74625726d..df2149d0a45072a813eda88bbe38e7fef584cdd2 100644 (file)
@@ -5,15 +5,19 @@ module LeapCli
     desc 'Compiles node configuration files into hiera files used for deployment'
     command :compile do |c|
       c.action do |global_options,options,args|
-        # these must come first
-        update_compiled_ssh_configs
-
-        # export generated files
-        manager.export_nodes
-        manager.export_secrets
+        compile_hiera_files
       end
     end
 
+    def compile_hiera_files(nodes=nil)
+      # these must come first
+      update_compiled_ssh_configs
+
+      # export generated files
+      manager.export_nodes(nodes)
+      manager.export_secrets
+    end
+
     def update_compiled_ssh_configs
       update_authorized_keys
       update_known_hosts
index f94465f161482518fd13a65deb573f8dd9a49c2e..cc2ea9603746a323a69e8fba8d57e94ece599ca7 100644 (file)
@@ -16,17 +16,18 @@ module LeapCli
           end
         end
 
-        nodes.each_node do |node|
-          assert_files_exist! Path.named_path([:hiera, node.name]), :msg => 'try running `leap compile`'
-        end
+        compile_hiera_files(nodes)
 
         ssh_connect(nodes) do |ssh|
-          ssh.leap.assert_initialized
+          ssh.leap.log :checking, 'node' do
+            ssh.leap.assert_initialized
+          end
 
           # sync hiera conf
-          ssh.leap.log :updating, "hiera.yaml" do
+          ssh.leap.log :syching, "hiera.yaml" do
             ssh.leap.rsync_update do |server|
               node = manager.node(server.host)
+              ssh.leap.log Path.relative_path([:hiera, node.name]) + ' -> ' + node.name + ':/etc/leap/hiera.yaml'
               {:source => Path.named_path([:hiera, node.name]), :dest => "/etc/leap/hiera.yaml"}
             end
           end
index 39dbcd2f10bbe1bda279794979f9ac7ab689c1bb..adda9bd3713e8b43faf58966277f95f4b739a067 100644 (file)
@@ -53,23 +53,39 @@ module LeapCli
       #
       # save compiled hiera .yaml files
       #
-      def export_nodes
-        existing_hiera = Dir.glob(Path.named_path([:hiera, '*'], @provider_dir))
-        existing_files = Dir.glob(Path.named_path([:node_files_dir, '*'], @provider_dir))
+      # if a node_list is specified, only update those .yaml files.
+      # otherwise, update all files, destroying files that are no longer used.
+      #
+      def export_nodes(node_list=nil)
         updated_hiera = []
         updated_files = []
-        self.each_node do |node|
+        existing_hiera = nil
+        existing_files = nil
+
+        unless node_list
+          node_list = self.nodes
+          existing_hiera = Dir.glob(Path.named_path([:hiera, '*'], @provider_dir))
+          existing_files = Dir.glob(Path.named_path([:node_files_dir, '*'], @provider_dir))
+        end
+
+        node_list.each_node do |node|
           filepath = Path.named_path([:node_files_dir, node.name], @provider_dir)
-          updated_files << filepath
           hierapath = Path.named_path([:hiera, node.name], @provider_dir)
-          updated_hiera << hierapath
           Util::write_file!(hierapath, node.dump)
+          updated_files << filepath
+          updated_hiera << hierapath
         end
-        (existing_hiera - updated_hiera).each do |filepath|
-          Util::remove_file!(filepath)
+
+        # remove files that are no longer needed
+        if existing_hiera
+          (existing_hiera - updated_hiera).each do |filepath|
+            Util::remove_file!(filepath)
+          end
         end
-        (existing_files - updated_files).each do |filepath|
-          Util::remove_directory!(filepath)
+        if existing_files
+          (existing_files - updated_files).each do |filepath|
+            Util::remove_directory!(filepath)
+          end
         end
       end