11

I am following exact syntax but seeing some strange behavior while adding role to one of my nodes

I am running following command which should ideally add role - webserver to do_node

knife node run_list add do_node 'role[webserver]'

But instead this is what is returned:

do_node:
 run_list: recipe[roles]

Also the show node command shows something gone wrong:

Run List:    recipe[roles]
Roles:

My workstation is a Win7 machine & using the hosted chef. Tried multiple times but same thing. Tried verbose output which does not reveal a whole lot!

Vishal Biyani
  • 4,297
  • 28
  • 55

1 Answers1

11

What is likely happening is that

role[webserver]

is being interpreted as a glob and is completing to the 'roles' directory in your chef directory. Thus, from knife's perspective, you've entered:

knife node run_list add do_node roles

which it upconverts to 'recipe[roles]'. Typically single quotes avoids this type of globbing, but I've seen issue crop up with mingw. You can confirm that this is the problem by trying to add a role that won't match a folder in your current directory:

knife node run_list add do_node 'role[foo]'

The best way to quote your original command depends a bit on your shell and terminal setup, but you may try the following:

knife node run_list add do_node '"role[webserver]"'

or (with double-quotes on the outside of the run list item)

knife node run_list add do_node "'role[webserver]'"

There are a number of bugs filed against this in the Chef issue tracker. Here is one: https://tickets.opscode.com/browse/CHEF-4277

Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93
Steven D
  • 336
  • 3
  • 4
  • Thanks a lot, that's quite close - you spotted the problem right. Though the '"role[webserver]"' is not working on my machine - doing the same thing as earlier! Need – Vishal Biyani Oct 29 '14 at 05:16
  • 2
    I think "'role[webserver]'" did the trick instead of '"role[webserver]"' – Vishal Biyani Oct 29 '14 at 05:57
  • 2
    Like (I think) @vishal.biyani commented, `"'role[webserver]'"` (i.e. with the double-quotes on the *outside*) worked in a MINGW32 ("Git Bash") terminal window, but not with the double-quotes on the inside. – Kenny Evitt Dec 11 '15 at 17:33