chef-workstation
chef-workstation copied to clipboard
Chef install Failed to generate Policyfile.lock: kitchen test suite policyfile
Description
Running
kitchen test global-ubuntu-1804
Fails to build Policyfile.lock.
ChefDK Version
$ chef --version
Chef Development Kit Version: 3.11.3
chef-client version: 14.13.11
delivery version: master (9d07501a3b347cc687c902319d23dc32dd5fa621)
berks version: 7.0.8
kitchen version: 1.25.0
inspec version: 3.9.3
Platform Version
Ubuntu 18.04 ChefDK 3.11.3
Replication Case
.kitchen.yml
contains:
---
driver:
name: dokken
privileged: true
env: [CHEF_LICENSE=accept]
transport:
name: dokken
provisioner:
name: dokken
deprecations_as_errors: true
verifier:
name: inspec
platforms:
-
name: ubuntu-18.04
driver:
image: dokken/ubuntu-18.04
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install sudo -y
suites:
- name: global
provisioner:
policyfile: test/fixtures/cookbooks/test/policyfiles/global.rb
verifier:
inspec_tests:
- test/integration/global
attributes:
test/fixtures/cookbooks/test/policyfiles/global.rb
contains:
name 'Test Global Recipe'
path = File.expand_path('base.rb', __dir__)
instance_eval(IO.read(path))
#include_policy 'base', path: '.'
# The run list is also ignored by ChefSpec but you need to specify one.
run_list 'test::global'
test/fixtures/cookbooks/test/policyfiles/base.rb
contains:
cookbook 'test', path: '.'
cookbook 'jlenv', path: '../../../../'
Stacktrace
$ chef install /home/<user>/src/jlenv-cookbook/test/fixtures/cookbooks/test/policyfiles/global.rb
Building policy Test Global Recipe
Expanded run list: recipe[test::global]
Caching Cookbooks...
Installing test >= 0.0.0 from path
Error: Failed to generate Policyfile.lock
Reason: (CookbookOmnifetch::NotACookbook) The resource at '/home/<user>/src/jlenv-cookbook/test/fixtures/cookbooks/test/policyfiles' does not appear to be a valid cookbook. Does it have a metadata.rb?
This is probably a bug with the policyfile path trying to find the cookbook and doing that incorrectly, but need to confirm. Might be a bug with Test Kitchen - if so, we'll move this to that repo
Is this issue fixed or is there a workaround on this yet? I am facing the same issue when I am behind a proxy and trying to access supermarket for accessing a cookbook, 'kitchen converge' fails with the following error : STDERR: Error: Failed to generate Policyfile.lock
Note: This is a sporadic issue. At times, 'kitchen converge' succeeds without any error and Policyfile.lock is generated with new revision id.
I normally get around this by renaming the Policyfile.rb and inserting a runlist in the kitchen.yml file under suites as follows:
suites:
- name: default
run_list:
- recipe[cookbook::recipe] verifier: inspec_tests: - test/integration/default attributes:
@tyler-ball : This does not appear to be restricted to Test Kitchen....
@mejerome Thanks for sharing that workaround.
This issue also appears to occur when running Chef-Zero and using a policy file.
The command that fails is:
$ sudo /opt/chefdk/bin/chef install --debug --config /etc/chef/client.rb ./policyfiles/${POLICY_NAME}.rb
Add to Developer run list: recipe[consul-vault::default]
Building policy vault-001
Expanded run list: recipe[consul-vault::default]
Caching Cookbooks...
Installing consul-vault >= 0.0.0 from path
Error: Failed to generate Policyfile.lock
Reason: (CookbookOmnifetch::NotACookbook) The resource at '/opt/chef-repo/developer-cookbooks/consul-vault' does not appear to be a valid co
okbook. Does it have a metadata.rb?
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/cookbook-omnifetch-0.9.1/lib/cookbook-omnifetch/base.rb:69:in `validate_cached!'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/cookbook-omnifetch-0.9.1/lib/cookbook-omnifetch/path.rb:18:in `install'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile/cookbook_location_specification.rb:81:in `ensure_cached'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_compiler.rb:378:in `block in cache_fixed_version_cookboo
ks'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_compiler.rb:376:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_compiler.rb:376:in `cache_fixed_version_cookbooks'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_compiler.rb:231:in `graph_solution'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_compiler.rb:178:in `install'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_services/install.rb:102:in `generate_lock_and_install'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/policyfile_services/install.rb:63:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/command/install.rb:80:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/command/base.rb:63:in `run_with_default_options'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/lib/chef-dk/cli.rb:74:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-dk-4.8.23/bin/chef:25:in `<top (required)>'
/opt/chefdk/bin/chef:351:in `load'
/opt/chefdk/bin/chef:351:in `<main>'
where /etc/chef/client.rb
is:
$ cat /etc/chef/client.rb
node_name ENV['POLICY_NAME']
policy_name ENV['POLICY_NAME']
policy_group 'local'
policy_document_native_api true
checksum_path '/opt/chef-repo/checksums'
chef_server_url 'http://127.0.0.1:8889'
chef_license 'accept'
client_name ENV['POLICY_NAME']
cookbook_path '/opt/chef-repo/cookbooks'
data_bag_path '/opt/chef-repo/data_bags'
encrypted_data_bag_secret '/opt/chef-repo/data_bags/encrypted_data_bag_secret'
environment_path '/opt/chef-repo/environments'
file_backup_path '/opt/chef-repo/backup'
file_cache_path '/opt/chef-repo/cache'
log_level :debug
log_location '/var/log/chef-client.log'
nodes_path '/opt/chef-repo/nodes'
role_path '/opt/chef-repo/roles'
use_policyfile true
verify_api_cert false
versioned_cookbooks true
and where /var/chef/solo.json
is:
$ cat /var/chef/solo.json
// Copyright (c) 2020-present Begley Brothers Inc.
{"policy_name":"vault-001","policy_group":"local"}
Platform Version
$ chef --version
ChefDK version: 4.8.23
Chef Infra Client version: 15.11.8
Chef InSpec version: 4.19.0
Test Kitchen version: 2.5.4
Foodcritic version: 16.2.0
Cookstyle version: 5.23.0