liondgr8
liondgr8

Reputation: 123

How to pass attributes in chef-client without JSON file?

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 ?

Upvotes: 12

Views: 9313

Answers (2)

user2066657
user2066657

Reputation: 479

This should work:

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

YMMV

Upvotes: 1

cassianoleal
cassianoleal

Reputation: 2566

Have you tried piping the JSON to STDIN?

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

Upvotes: 33

Related Questions