cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

Chef file_cache_path and others are set to non-standard values by default

Open RulerOf opened this issue 1 year ago • 1 comments

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

  1. Pack a server image using an /etc/chef/client.rb that does not configure a file_cache_path. Data will be cached in /var/chef/cache
  2. Deploy that server image with cloud-init and do not configure a file_cache_path. /etc/chef/client.rb will be rendered with file_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

RulerOf avatar Mar 22 '24 20:03 RulerOf

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.

blackboxsw avatar Mar 25 '24 14:03 blackboxsw