Chef file_cache_path and others are set to non-standard values by default
Bug report
During image packing, our chef code downloads files from the internet into the chef file_cache_path default location, /var/chef/cache.
Later, when the servers come up from the packed image using cloud-init, everything that should be cached is being re-downloaded.
Steps to reproduce the problem
- Pack a server image using an
/etc/chef/client.rbthat does not configure afile_cache_path. Data will be cached in/var/chef/cache - Deploy that server image with cloud-init and do not configure a
file_cache_path./etc/chef/client.rbwill be rendered withfile_cache_path "/var/cache/chef".
https://github.com/canonical/cloud-init/blob/main/cloudinit/config/cc_chef.py#L61
More Details
As shown on one of my servers, this is the chef section of the user-data:
chef:
chef_license: accept
exec: true
exec_arguments: []
initial_attributes: REDACTED
install_type: omnibus
run_list:
- recipe[REDACTED]
server_url: https://redacted
validation_cert: REDACTED
validation_name: REDACTED
Cloud-init renders a file with the non-default cache path:
[root@ip-172-17-6-13 /] :) head -2 /etc/chef/client.rb
# Created by cloud-init v. 19.3-46.amzn2.0.1 on Tue, 05 Mar 2024 20:23:33 +0000
log_level :info
[root@ip-172-17-6-13 /] :) grep file_cache_path /etc/chef/client.rb
file_cache_path "/var/cache/chef"
Chef respects this config:
[root@ip-172-17-6-13 /] :( chef-shell -z
loading configuration: /etc/chef/client.rb
<snip>
chef (18.4.2)> Chef::Config["file_cache_path"]
=> "/var/cache/chef"
Removing file_cache_path from my client.rb brings back the expected result:
[root@ip-172-17-6-13 /] :) sed -i '/file_cache_path/d' /etc/chef/client.rb
[root@ip-172-17-6-13 /] :) chef-shell -z
loading configuration: /etc/chef/client.rb
<snip>
chef (18.4.2)> Chef::Config["file_cache_path"]
=> "/var/chef/cache"
Environment details
- Cloud-init version:
19.3-46.amzn2.0.1 - Operating System Distribution: Amazon Linux 2
- Cloud provider, platform or installer type: AWS
Thank you for this bug @RulerOf and making cloud-init better. It does appear this is a typo in the original chef defaults and I believe should be corrected to /var/chef/cache in cloud-init defaults.