rubygemschef-infrachef-recipetest-kitchen

chef test-kitchen run only default recipe


I installed chef workstation on windows, I have 2 recipes, default and install_nginx, when I run kitchen converge, kitchen only executes the default recipe. For security I do kitchen verify and it gives me an error because the test script verificase nginx is installed. Can you tell me why? this is miy kitchen.yml

---
driver:
  name: vagrant

  network:
    - ["forwarded_port", {guest: 80, host: 8080}]

provisioner:
  name: chef_zero

verifier:
  name: inspec

platforms:
  - name: hashicorp/precise32

suites:
  - name: default
    run_list:
        -recipe[chef-example::default]
        -recipe[chef-example::install_nginx]
    verifier:
      inspec_tests:
        - test/integration/default
    attributes:

this is my PolicyFile.rb

# Policyfile.rb - Describe how you want Chef Infra Client to build your system.
#
# For more information on the Policyfile feature, visit
# https://docs.chef.io/policyfile.html

# A name that describes what the system you're building with Chef does.
name 'chef-example'

# Where to find external cookbooks:
default_source :supermarket

# run_list: chef-client will run these recipes in the order specified.
run_list 'chef-example::default'

# Specify a custom source for a single cookbook:
cookbook 'chef-example', path: '.'

Solution

  • If Test Kitchen uses policyfile, then it takes the run_list also from it. In this case run_list inside the kitchen.yml is ignored. If you need to have different suites with different run_lists with policyfiles, you need to use several policyfiles. In this case I recommend having 1 folder policyfiles with different policies there, and the following configuration in the kitchen.yml

    suites:
      - name: default
        provisioner:
          policyfile_path: policyfiles/default.rb
        verifier:
          inspec_tests:
            - test/integration/default   # can be omitted, as this is default place to look for tests
        attributes:
      - name: test1
        provisioner:
          policyfile_path: policyfiles/test1.rb
        verifier:
          inspec_tests:
            - test/integration/test1     # can be omitted, as this is default place to look for tests
        attributes: