Adding a role in kitchenci framework


#1

I am tryign to add a role in kitchenci and add few recipes for the role. I have a folder by name “roles” under my cookbook and have the role defined as follows in test.json file:
/kitchentest_erp# cat roles/test.json
{
_ “name”: “test”,_
_ “default_attributes”: { },_
_ “override_attributes”: { },_
_ “json_class”: “Chef::Role”,_
_ “description”: “This is just a test role, no big deal.”,_
_ “chef_type”: “role”,_
_ “run_list”: [ “recipe[kitchentest_erp::default]” ]_
}

I have included this role in the .kitchen.yml file under the cookbook folder as shown below:

provisioner:
_ name: chef_zero_
_ always_update_cookbooks: true_
_ roles_path: ./roles/_

suites:
_ - name: default_
_ run_list:_
_ - role[kitchentest_erp::test]_

However when i run Kitchen converge i get error as :
ERROR: Role kitchentest_erp::test (included by ‘top level’) is in the runlist but does not exist. Skipping expand.

_ ================================================================================_
_ Error expanding the run_list:_
_ ================================================================================_

_ Missing Role(s) in Run List:_
_ ----------------------------_
_ * kitchentest_erp::test included by ‘top level’_

_ Original Run List_
_ -----------------_
_ * role[kitchentest_erp::test]_

_ System Info:_
_ ------------_
_ chef_version=13.8.5_
_ platform=suse_
_ platform_version=12.2_
_ ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]_
_ program_name=chef-client worker: ppid=12727;start=11:08:46;_
_ executable=/opt/chef/bin/chef-client_

_ Running handlers:_
_ [2018-06-18T11:08:48+00:00] ERROR: Running exception handlers_
_ Running handlers complete_
_ [2018-06-18T11:08:48+00:00] ERROR: Exception handlers complete_
_ Chef Client failed. 0 resources updated in 01 seconds_
_ [2018-06-18T11:08:48+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out_
_ [2018-06-18T11:08:48+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report_
_ [2018-06-18T11:08:48+00:00] ERROR: The expanded run list includes nonexistent roles: kitchentest_erp::test_

How do I add role and run kitchen converge successfully ?


#2

I ran into the same error

You need to add :

roles_path: “…/…/roles” to your .kitchen.yml file under the suites:


#3

You could also move the role into a test/integration/roles directory. That’s the default location that test kitchen looks at for test configs.