1

How can I get list of nodes, that have a specific role?

It could be got with something like that:

for node in `knife node list`; do
  [[ -n "`knife node show $node | grep $ROLE_NAME`" ]] &&  echo $node
done

Is there a way to doing it via knife without bash overhead?

2 Answers2

7

There is a solution:

knife search node "roles:$ROLE_NAME"
1

The header from "knife search" is output to stderr, so you can use

knife search "role:$ROLE_NAME" -i 2>/dev/null

to just return a list of nodes. Useful if you want to wrap that into a for statement:

for n in $(knife search "role:$ROLE_NAME" -i 2>/dev/null); do
  // do something here
done
Gary
  • 11
  • 1