Adding role to node does not work
Asked Answered
U

1

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!

Upcountry answered 28/10, 2014 at 18:18 Comment(0)
E
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

Enact answered 28/10, 2014 at 22:59 Comment(3)
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! NeedUpcountry
I think "'role[webserver]'" did the trick instead of '"role[webserver]"'Upcountry
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.Swithbert

© 2022 - 2024 — McMap. All rights reserved.