How to pass user input parameter at the time of chef-client run on node for windows server


Can you please tell me how to pass run-time user input while we are running chef-client on windows node for power-shell script without passing JSON file path?

We had tried
chef-client -j

This works proper for me.
but I want windows equivalent of this command

echo’{“attribue1”:“value1”, “attribute2”:“value2”}’ | chef-client -j /dev/stdin (This is for linux)

Thanks in Advance

1 Like

I have not tested this at all, but it might set you in the right direction…
In PowerShell you would need a hash table. This can either be initialized blank and populated later or pre-populated. Here is the info in regards to a pre-populated hash table

# Pre-populated hash table
$array_name = @{ KeyName1 = 'value1'; KeyName2 = 'value2'; KeyName3 = 'value3';}
# pass the array to the chef-client command
chef-client -j $array_name

If that doesn’t work, there are also some other paths to have a quick look down:

# Pre-populated hash table
$array_name = @{ KeyName1 = 'value1'; KeyName2 = 'value2'; KeyName3 = 'value3';}

# Convert the hash table to a json object
$json_out = $array_name | ConvertTo-Json

#Type to review data within the json object

# This is the output I got from the ConvertTo-Json
    "KeyName2":  "value2",
    "KeyName1":  "value1",
    "KeyName3":  "value3"

# Run the command
chef-client -j $json_out

If this doesn’t work, then you might want to look search for the windows equivalent of /dev/stdin in Powershell.

Here is a link to info regarding Powershell Hash Tables that may also assist with further functionality etc.

Here is the man page for ConvertTo-Json which may assist you in refining my crude code.

Hopefully I have given you a path that leads to resolution.

This isn’t really a thing, or at least isn’t how chef-client is expected to be used. It assumes input data comes from Chef Server, not locally. The -j option is mostly there for certain types of self-registration and bootstrapping, I wouldn’t use it like this. If you really need to send local data in to Chef I would either use a config file that your recipe code reads from or use environment variables.