diff options
-rw-r--r-- | lib/leap_cli/commands/compile.rb | 16 | ||||
-rw-r--r-- | lib/leap_cli/commands/deploy.rb | 11 | ||||
-rw-r--r-- | lib/leap_cli/config/manager.rb | 36 |
3 files changed, 42 insertions, 21 deletions
diff --git a/lib/leap_cli/commands/compile.rb b/lib/leap_cli/commands/compile.rb index 45e4f2b..df2149d 100644 --- a/lib/leap_cli/commands/compile.rb +++ b/lib/leap_cli/commands/compile.rb @@ -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 diff --git a/lib/leap_cli/commands/deploy.rb b/lib/leap_cli/commands/deploy.rb index f94465f..cc2ea96 100644 --- a/lib/leap_cli/commands/deploy.rb +++ b/lib/leap_cli/commands/deploy.rb @@ -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 diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 39dbcd2..adda9bd 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -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 |