summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-09-23 12:50:54 -0700
committerdanielsdeleo <dan@chef.io>2015-09-24 12:37:26 -0700
commit14d7baab6365e0b4146990a5306f80a7f0d09a82 (patch)
tree70292b704f85ab6c06b6b52f3a0d89e418c954f1
parent4141c33df8e31b78359fb316315547d36f837df6 (diff)
downloadchef-14d7baab6365e0b4146990a5306f80a7f0d09a82.tar.gz
Don't pass -E to chef-client unless given an environment
Chef::PolicyBuilder::Policyfile requires `Chef::Config[:environment]` to be nil or empty, in order to prevent confusion that could arise from using two conflicting features. Because `chef-client` merges CLI options to `Chef::Config` automatically, running `chef-cient -E _default` causes `Chef::Config[:environment]` to be non-nil, resulting in chef-client emitting this error when bootstrapping: ``` 192.168.99.143 Unexpected Error: 192.168.99.143 ----------------- 192.168.99.143 Chef::PolicyBuilder::Policyfile::UnsupportedFeature: Policyfile does not work with Chef Environments ``` For non-policyfile users, this should behave the same as before since Chef will just default to the `_default` environment (this gets set via Node#initialize) if none is specified.
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb4
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb8
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index d85ee91490..d210b9418f 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -40,7 +40,7 @@ class Chef
end
def bootstrap_environment
- @chef_config[:environment] || '_default'
+ @chef_config[:environment]
end
def validation_key
@@ -128,7 +128,7 @@ CONFIG
client_path = @chef_config[:chef_client_path] || 'chef-client'
s = "#{client_path} -j /etc/chef/first-boot.json"
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
- s << " -E #{bootstrap_environment}"
+ s << " -E #{bootstrap_environment}" unless bootstrap_environment.nil?
s
end
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index a93e5362a9..0433ef9983 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -38,14 +38,14 @@ describe Chef::Knife::Core::BootstrapContext do
expect{described_class.new(config, run_list, chef_config)}.not_to raise_error
end
- it "runs chef with the first-boot.json in the _default environment" do
- expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -E _default"
+ it "runs chef with the first-boot.json with no environment specified" do
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json"
end
describe "when in verbosity mode" do
let(:config) { {:verbosity => 2} }
it "adds '-l debug' when verbosity is >= 2" do
- expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -l debug -E _default"
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -l debug"
end
end
@@ -70,7 +70,7 @@ EXPECTED
describe "alternate chef-client path" do
let(:chef_config){ {:chef_client_path => '/usr/local/bin/chef-client'} }
it "runs chef-client from another path when specified" do
- expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json -E _default"
+ expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json"
end
end