Object unchanged when running knife client edit

匆匆过客 提交于 2019-12-12 03:22:20

问题


I'm running knife client edit command to edit a node in Chef to set admin permissions. I would like to do this programmatically so my intention is to add this command to a shell script if I can make it work.

The previous state of the node is (UPDATE):

$ knife client show -Fj my_node
{
  "name": "my_node",
  "public_key": "-----BEGIN PUBLIC KEY-----\n...key...\n-----END PUBLIC KEY-----\n",
  "validator": false,
  "admin": false,
  "json_class": "Chef::ApiClient",
  "chef_type": "client"
}

When running the command it says that the object is unchanged and after checking the node with knife client I can verify that still has the admin attribute set to false:

$ knife client edit -d my_node < my_node.json
Object unchanged, not saving

The content of my_node.json file is:

{
  "name": "my_node",
  "public_key": "-----BEGIN PUBLIC KEY-----\n...key...\n-----END PUBLIC KEY-----\n",
  "validator": false,
  "admin": true,
  "json_class": "Chef::ApiClient",
  "chef_type": "client"
}

I don't know how to make this piece work. Any help on this will be very much appreciated.

NOTE: $ knife --version Chef: 12.2.1

UPDATE: I couldn't find an accepted answer in this thread which is quite similar.

UPDATE 2: I tried these other ways as well with no luck at all (using same json file):

$ cat my_node.json | knife client edit my_node -d
Object unchanged, not saving

$ knife client edit my_node -d < my_node.json
Object unchanged, not saving

回答1:


If you already got the file with the content you need, there is a trick to use it.

knife client edit -e "cp my_node.json"

Explanation on how interactive editing works on an app (knife in this case):

  1. The app starts on foreground the command on EDITOR environment variable passing a temporary file as argument
  2. When the command ends, the app opens the temporary file and uses it

So if all you want is changing a word, you can use sed instead:

knife client edit -e "sed -i  's/\"admin\":\s*false/\"admin\": true/'"



回答2:


There is no difference between your my_node.json and your my_node settings. Change a value and try again.



来源:https://stackoverflow.com/questions/31744371/object-unchanged-when-running-knife-client-edit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!