12

I know we can pass node attributes in chef-{client/solo} with --json-attributes(-j) flag. This flag always expect a JSON file as input. Is their any method I can directly pass the attributes as JSON objects.

I tried doing it. For eg:

chef-client -j {"attr":"value"} 

But it ends up with a failure message as:

FATAL: I cannot find {"attr":"value"}

As it expects a JSON file. I need to pass JSON objects as in our env I can't create a json file. I don't want to use attributes/role/environment files as well. Is there any other way to pass the attributes ?

Prabindh
  • 3,356
  • 2
  • 23
  • 25
liondgr8
  • 123
  • 1
  • 9
  • As a workaround you could try to upload the JSON somewhere else and enter the URL of the JSON. May that works? – Yser Feb 24 '14 at 11:34

2 Answers2

33

Have you tried piping the JSON to STDIN?

echo '{"attr":"value"}' | chef-client -j /dev/stdin

cassianoleal
  • 2,556
  • 19
  • 22
1

This should work:

knife ssh $VM -- chef-client -j '<(echo \{\"attr\":\"value\"\})' --no-fork

YMMV

user2066657
  • 444
  • 1
  • 4
  • 23