Adding new role to run_list adds 'recipe[roles]' instead of 'role[rolename]'

Running Chef server 12.15 on RHEL7.3, using ChefDK on cygwin / Windows 7.

Going through Chef tutorial, I am trying to add a role named test-webserver to a run_list for a server testserver .

However, trying to add role[test-webserver] to the run_list instead attempts to add a recipe named roles to the runlist, even though roles is not a defined recipe.

$ knife node run_list set testserver 'role[test-webserver]'
testserver:
  run_list: recipe[roles]

There, I would expect run_list: role[test-webserver] to show up instead of run_list: recipe[roles].

The test-webserver role is defined role as below.

$ knife role show test-webserver
chef_type:           role
default_attributes:
  chef_client:
    interval: 300
    splay:    60
description:         Web server role.
env_run_lists:
json_class:          Chef::Role
name:                test-webserver
override_attributes:
run_list:
  recipe[chef-client::default]
  recipe[chef-client::delete_validation]
  recipe[learn_chef_httpd::default]

Running chef-client on the testserver causes an error because there is no cookbook called roles.

[testserver ~]$ sudo chef-client
[2017-07-20T10:53:45+09:00] INFO: Forking chef instance to converge...
Starting Chef Client, version 13.2.20
[2017-07-20T10:53:45+09:00] INFO: *** Chef 13.2.20 ***
[2017-07-20T10:53:45+09:00] INFO: Platform: x86_64-linux
[2017-07-20T10:53:45+09:00] INFO: Chef-client pid: 48215
[2017-07-20T10:53:45+09:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
[2017-07-20T10:54:06+09:00] INFO: Run List is [recipe[roles]]
[2017-07-20T10:54:06+09:00] INFO: Run List expands to [roles]
[2017-07-20T10:54:06+09:00] INFO: Starting Chef Run for testserver
[2017-07-20T10:54:06+09:00] INFO: Running start handlers
[2017-07-20T10:54:06+09:00] INFO: Start handlers complete.
[2017-07-20T10:54:06+09:00] INFO: Error while reporting run start to Data Collector. URL: https://mychefserver.example.com/organizations/redacted/data-collector Exception: 404 -- 404 "Not Found"  (This is normal if you do not have Chef Automate)
resolving cookbooks for run list: ["roles"]

================================================================================
Error Resolving Cookbooks for Run List:
================================================================================

Missing Cookbooks:
------------------
The following cookbooks are required by the client but don't exist on the server:
* roles


Expanded Run List:
------------------
* roles

System Info:
------------
chef_version=13.2.20
platform=redhat
platform_version=7.3
ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
program_name=chef-client worker: ppid=48210;start=10:53:45;
executable=/opt/chef/bin/chef-client


Running handlers:
[2017-07-20T10:54:07+09:00] ERROR: Running exception handlers
Running handlers complete
[2017-07-20T10:54:07+09:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 21 seconds
[2017-07-20T10:54:07+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2017-07-20T10:54:07+09:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-07-20T10:54:07+09:00] ERROR: 412 "Precondition Failed"
[2017-07-20T10:54:07+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Why is the role not being added to the run_list, and why is a non-existent roles recipe being added instead?

How can I add the desired cookbooks, included in the test-webserver role, to the target server testserver?

Thanks

Can you verify that you have put single quote around role[test-webserver]? I have received the same error you have, but only when I didn’t use single quotes around it.

Verified I was using single quotes. Also, checked with double quotes and no quotes and same results for all.

$ knife node run_list remove testserver 'recipe[roles]'
testserver:
  run_list:
$ knife node run_list set testserver 'role[test-webserver]'
testserver:
  run_list: recipe[roles]
$ knife node run_list remove testserver 'recipe[roles]'
testserver:
  run_list:
$ knife node run_list set testserver "role[test-webserver]"
testserver:
  run_list: recipe[roles]
$ knife node run_list remove testserver 'recipe[roles]'
testserver:
  run_list:
$ knife node run_list set testserver role[test-webserver]
testserver:
  run_list: recipe[roles]
$ knife node run_list remove testserver 'recipe[roles]'
testserver:
  run_list:

when you run: knife role list
can you see the role test-webserver ?
and can you check if the role test-webserver name in the .json file named correctly? “name”: “test-webserver”, instead of roles?

yes, it shows up in knife role list, and from what I can tell is named correctly and defined as a Role in the creation json file, and after creation.

$ knife role delete test-webserver
Do you really want to delete test-webserver? (Y/N) y
Deleted role[test-webserver]

$ cat roles/test-webserver.json
{
   "name": "test-webserver",
   "description": "Web server role.",
   "json_class": "Chef::Role",
   "default_attributes": {
     "chef_client": {
       "interval": 300,
       "splay": 60
     }
   },
   "override_attributes": {
   },
   "chef_type": "role",
   "run_list": ["recipe[chef-client::default]",
                "recipe[chef-client::delete_validation]",
                "recipe[learn_chef_httpd::default]"
   ],
   "env_run_lists": {
   }
}

$ knife role from file roles/test-webserver.json
Updated Role test-webserver

$ knife role list
test-webserver

$ knife role show test-webserver
chef_type:           role
default_attributes:
  chef_client:
    interval: 300
    splay:    60
description:         Web server role.
env_run_lists:
json_class:          Chef::Role
name:                test-webserver
override_attributes:
run_list:
  recipe[chef-client::default]
  recipe[chef-client::delete_validation]
  recipe[learn_chef_httpd::default]


$ knife node run_list set testserver 'role[test-webserver]'
testserver:
  run_list: recipe[roles]

Nothing jumps out at me as inappropriately defined or stored…

Found a way to set up the proper run list at least, though it doesn’t prevent the unexpected behavior of knife node run_list set nodename 'role[rolename]'.

Using knife node edit testserver allows manually editing the file to say the following:

{
  "name": "testserver",
  "chef_environment": "_default",
  "normal": {
    "tags": [

    ]
  },
  "policy_name": null,
  "policy_group": null,
  "run_list": [
  "role[test-webserver]"
]

}

Instead of having recipe[roles] in the run list. After making the above change, running chef-client on testserver was successful in establishing the role and desired settings.

I’d still like to know why using knife node run_list add ... does not work however, any help greatly appreciated

hello @ chilchey i hit the same error ..what did you change when you edit the node. i see my node edit output where run_list is empty >.

"name": "lvaristaeos",
"chef_environment": "_default",
"normal": {
"tags": [

]

},
"policy_name": null,
"policy_group": null,
"run_list": [
"recipe[eos::switchconfig_static]"
]