From dd3d78265940b5764ebcbacd8fcc007d19c37291 Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Wed, 12 Jul 2017 15:27:10 +0200 Subject: [PATCH 1/5] Added exception if chef.node_path is defined on Vagrantfile but the directory does not exist locally --- plugins/provisioners/chef/provisioner/chef_zero.rb | 7 +++++++ templates/locales/en.yml | 2 ++ 2 files changed, 9 insertions(+) diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb index 70fff6854..43bdf648e 100644 --- a/plugins/provisioners/chef/provisioner/chef_zero.rb +++ b/plugins/provisioners/chef/provisioner/chef_zero.rb @@ -35,6 +35,7 @@ module VagrantPlugins upload_encrypted_data_bag_secret setup_json setup_zero_config + verify_chef_nodes_folder run_chef_zero delete_encrypted_data_bag_secret end @@ -101,6 +102,12 @@ module VagrantPlugins end end + def verify_chef_nodes_folder + if not File.exists? @config.nodes_path[0][1] + raise ChefError, :missing_chef_node_folder + end + end + protected # Extracts only the remote paths from a list of folders diff --git a/templates/locales/en.yml b/templates/locales/en.yml index deae43256..a05c267c2 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2192,6 +2192,8 @@ en: running_solo_again: "Running chef-solo again (failed to converge)..." running_zero: "Running chef-client (local-mode)..." running_zero_again: "Running chef-client (local-mode) again (failed to converge)..." + missing_chef_node_folder: |- + Nodes folder that Chef requires is missing in this Vagrant project missing_shared_folders: |- Shared folders that Chef requires are missing on the virtual machine. This is usually due to configuration changing after already booting the From 3a5331cbb26cd8c9e54470883ecd4e86a635aba6 Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Wed, 12 Jul 2017 15:32:39 +0200 Subject: [PATCH 2/5] replaced not with ! in the if --- plugins/provisioners/chef/provisioner/chef_zero.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb index 43bdf648e..53eb81bf7 100644 --- a/plugins/provisioners/chef/provisioner/chef_zero.rb +++ b/plugins/provisioners/chef/provisioner/chef_zero.rb @@ -103,7 +103,7 @@ module VagrantPlugins end def verify_chef_nodes_folder - if not File.exists? @config.nodes_path[0][1] + if !File.exists? @config.nodes_path[0][1] raise ChefError, :missing_chef_node_folder end end From 94a94648ddf4204ebc3f10cead66d74b6b6aa6de Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Sat, 22 Jul 2017 07:58:38 +0200 Subject: [PATCH 3/5] change requested after a PR review --- plugins/provisioners/chef/provisioner/chef_zero.rb | 7 ------- templates/locales/en.yml | 2 -- 2 files changed, 9 deletions(-) diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb index 53eb81bf7..70fff6854 100644 --- a/plugins/provisioners/chef/provisioner/chef_zero.rb +++ b/plugins/provisioners/chef/provisioner/chef_zero.rb @@ -35,7 +35,6 @@ module VagrantPlugins upload_encrypted_data_bag_secret setup_json setup_zero_config - verify_chef_nodes_folder run_chef_zero delete_encrypted_data_bag_secret end @@ -102,12 +101,6 @@ module VagrantPlugins end end - def verify_chef_nodes_folder - if !File.exists? @config.nodes_path[0][1] - raise ChefError, :missing_chef_node_folder - end - end - protected # Extracts only the remote paths from a list of folders diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a05c267c2..deae43256 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2192,8 +2192,6 @@ en: running_solo_again: "Running chef-solo again (failed to converge)..." running_zero: "Running chef-client (local-mode)..." running_zero_again: "Running chef-client (local-mode) again (failed to converge)..." - missing_chef_node_folder: |- - Nodes folder that Chef requires is missing in this Vagrant project missing_shared_folders: |- Shared folders that Chef requires are missing on the virtual machine. This is usually due to configuration changing after already booting the From c9b65bd129b17a2dae9b152c9b94e1ae89985695 Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Sat, 22 Jul 2017 11:00:05 +0200 Subject: [PATCH 4/5] produce error when node_path is defined but the directory does not exist on disk locally --- plugins/provisioners/chef/config/chef_zero.rb | 7 +++++++ templates/locales/en.yml | 2 ++ .../provisioners/chef/config/chef_zero_test.rb | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/plugins/provisioners/chef/config/chef_zero.rb b/plugins/provisioners/chef/config/chef_zero.rb index 93a036cd7..d02f78f6f 100644 --- a/plugins/provisioners/chef/config/chef_zero.rb +++ b/plugins/provisioners/chef/config/chef_zero.rb @@ -79,6 +79,13 @@ module VagrantPlugins if !present?(Array(nodes_path)) errors << I18n.t("vagrant.config.chef.nodes_path_empty") + else + missing_paths = Array.new + nodes_path.each { |dir| missing_paths << dir[1] if !File.exists? dir[1] } + # If it exists at least one path on disk it's ok for Chef provisioning + if missing_paths.size == nodes_path.size + errors << I18n.t("vagrant.config.chef.nodes_path_missing", path: missing_paths.to_s) + end end if environment && environments_path.empty? diff --git a/templates/locales/en.yml b/templates/locales/en.yml index deae43256..f6da5f97a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1579,6 +1579,8 @@ en: Missing required value for `chef.nodes_path'. environment_path_missing: |- Environment path not found: %{path} + nodes_path_missing: |- + Path specified for `nodes_path` does not exist: %{path} environment_path_required: |- When 'environment' is specified, you must provide 'environments_path'. cookbooks_path_missing: |- diff --git a/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb b/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb index 1767da562..c674a2767 100644 --- a/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb +++ b/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb @@ -110,6 +110,17 @@ describe VagrantPlugins::Chef::Config::ChefZero do end end + context "when an element of nodes_path does not exist on disk" do + it "returns an error" do + nodes_path = ["/path/to/nodes/that/will/never/exist"] + subject.nodes_path = nodes_path + subject.finalize! + expect(errors).to include(I18n.t("vagrant.config.chef.nodes_path_missing", + path: nodes_path + )) + end + end + context "when the nodes_path is an empty array" do it "returns an error" do subject.nodes_path = [] From 7e436c6971da005eade184e3c728ef21ed5e69b9 Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Tue, 1 Aug 2017 20:36:38 +0200 Subject: [PATCH 5/5] fixed warnings about missing folders for Chef Solo and Zero --- plugins/provisioners/chef/provisioner/chef_solo.rb | 3 ++- templates/locales/en.yml | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb index 64876ffde..cc613af8a 100644 --- a/plugins/provisioners/chef/provisioner/chef_solo.rb +++ b/plugins/provisioners/chef/provisioner/chef_solo.rb @@ -87,7 +87,8 @@ module VagrantPlugins key = Digest::MD5.hexdigest(local_path) remote_path = "#{guest_provisioning_path}/#{key}" else - @machine.ui.warn(I18n.t("vagrant.provisioners.chef.cookbook_folder_not_found_warning", + appended_folder = "cookbooks" if appended_folder.nil? + @machine.ui.warn(I18n.t("vagrant.provisioners.chef.#{appended_folder}_folder_not_found_warning", path: local_path.to_s)) next end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f6da5f97a..04b05ed49 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2160,8 +2160,16 @@ en: The chef binary (either `chef-solo` or `chef-client`) was not found on the VM and is required for chef provisioning. Please verify that chef is installed and that the binary is available on the PATH. - cookbook_folder_not_found_warning: + cookbooks_folder_not_found_warning: "The cookbook path '%{path}' doesn't exist. Ignoring..." + nodes_folder_not_found_warning: + "The node path '%{path}' doesn't exist. Ignoring..." + data_bags_folder_not_found_warning: + "The databag path '%{path}' doesn't exist. Ignoring..." + roles_folder_not_found_warning: + "The role path '%{path}' doesn't exist. Ignoring..." + environments_folder_not_found_warning: + "The environment path '%{path}' doesn't exist. Ignoring..." json: "Generating chef JSON and uploading..." client_key_folder: "Creating folder to hold client key..." generating_node_name: |-