summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-10-12 20:43:09 -0700
committerTim Smith <tsmith84@gmail.com>2020-10-12 20:56:24 -0700
commitb93860e919d2fa2c6a878ac78140c1ef25036942 (patch)
tree0c55de20222522ac5611e1a09b1d98400dcebc5d
parentfbde8dc0c3da8ae96e1cda3d36338779dff65ff1 (diff)
downloadchef-b93860e919d2fa2c6a878ac78140c1ef25036942.tar.gz
Add additional_config property
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/linux.rb7
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/macos.rb7
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/windows.rb7
-rw-r--r--kitchen-tests/test/integration/end-to-end/default_spec.rb3
-rw-r--r--lib/chef/resource/chef_client_config.rb25
-rw-r--r--lib/chef/resource/support/client.erb1
6 files changed, 47 insertions, 3 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
index 71395d7364..4e096b1daa 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
@@ -88,6 +88,13 @@ include_recipe "::_chef_client_trusted_certificate"
chef_client_config "Create chef-client's client.rb" do
chef_server_url "https://localhost"
chef_license "accept"
+ additional_config <<~CONFIG
+ begin
+ require 'aws-sdk'
+ rescue LoadError
+ Chef::Log.warn "Failed to load aws-sdk."
+ end
+ CONFIG
end
chef_client_cron "Run chef-client as a cron job"
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/macos.rb b/kitchen-tests/cookbooks/end_to_end/recipes/macos.rb
index e06d1d1fc9..8307351ad7 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/macos.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/macos.rb
@@ -44,6 +44,13 @@ include_recipe "::_chef_client_trusted_certificate"
chef_client_config "Create chef-client's client.rb" do
chef_server_url "https://localhost"
chef_license "accept"
+ additional_config <<~CONFIG
+ begin
+ require 'aws-sdk'
+ rescue LoadError
+ Chef::Log.warn "Failed to load aws-sdk."
+ end
+ CONFIG
end
chef_client_launchd "Every 30 mins Infra Client run" do
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
index cc8643facf..486d680a3f 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -82,6 +82,13 @@ end
chef_client_config "Create chef-client's client.rb" do
chef_server_url "https://localhost"
chef_license "accept"
+ additional_config <<~CONFIG
+ begin
+ require 'aws-sdk'
+ rescue LoadError
+ Chef::Log.warn "Failed to load aws-sdk."
+ end
+ CONFIG
end
include_recipe "::_chef_client_trusted_certificate"
diff --git a/kitchen-tests/test/integration/end-to-end/default_spec.rb b/kitchen-tests/test/integration/end-to-end/default_spec.rb
index a3f60273ad..3a0848a7e9 100644
--- a/kitchen-tests/test/integration/end-to-end/default_spec.rb
+++ b/kitchen-tests/test/integration/end-to-end/default_spec.rb
@@ -7,4 +7,5 @@ client_rb = if os.windows?
describe file(client_rb) do
its("content") { should match(%r{chef_server_url = "https://localhost"}) }
its("content") { should match(/chef_license = "accept"/) }
-end
+ its("content") { should match(/require 'aws-sdk'/) }
+endx
diff --git a/lib/chef/resource/chef_client_config.rb b/lib/chef/resource/chef_client_config.rb
index 061c9a1851..6ba8128f83 100644
--- a/lib/chef/resource/chef_client_config.rb
+++ b/lib/chef/resource/chef_client_config.rb
@@ -47,12 +47,29 @@ class Chef
no_proxy %w(internal.example.dmz)
end
```
+
+ **Adding additional config content to the client.rb**:
+
+ ```ruby
+ chef_client_config 'Create client.rb' do
+ chef_server_url 'https://chef.example.dmz'
+ additional_config <<~CONFIG
+ # Extra config code to safely load a gem into the client run.
+ # Since the config is Ruby you can run any Ruby code you want via the client.rb.
+ # It's a great way to break things, so be careful
+ begin
+ require 'aws-sdk'
+ rescue LoadError
+ Chef::Log.warn "Failed to load aws-sdk."
+ end
+ CONFIG
+ end
+ ```
DOC
# @todo policy_file or policy_group being set requires the other to be set so enforce that.
# @todo all properties for automate report
# @todo add all descriptions
- # @todo add free form "additional_config" property
#
# @param [String, Symbol] prop_val the value from the property
@@ -181,6 +198,9 @@ class Chef
property :file_staging_uses_destdir, String,
description: "How file staging (via temporary files) is done. When `true`, temporary files are created in the directory in which files will reside. When `false`, temporary files are created under `ENV['TMP']`"
+ property :additional_config, String,
+ description: "Additional text to add at the bottom of the client.rb config. This can be used to run custom Ruby or to add less common config options"
+
action :create do
unless ::Dir.exist?(new_resource.config_directory)
directory new_resource.config_directory do
@@ -227,7 +247,8 @@ class Chef
report_handlers: new_resource.report_handlers,
run_path: new_resource.run_path,
ssl_verify_mode: new_resource.ssl_verify_mode,
- start_handlers: new_resource.start_handlers
+ start_handlers: new_resource.start_handlers,
+ additional_config: new_resource.additional_config
)
mode "0640"
action :create
diff --git a/lib/chef/resource/support/client.erb b/lib/chef/resource/support/client.erb
index 73c5c90f20..ed03302dcd 100644
--- a/lib/chef/resource/support/client.erb
+++ b/lib/chef/resource/support/client.erb
@@ -62,3 +62,4 @@ log_location = <%= @log_location.inspect %>
Chef::Log.error e
end
<% end -%>
+<%= @additional_config -%>