Search code examples
chef-infra

Can we automate updating the chef node attributes?


I have a node with the following json in chef nodes:

 {
  "name": "app-node-01",
  "chef_environment": "dev",
  "run_list": [
  "recipe[hello-world]"
],
  "normal": {
    "app_version": "1.0.0",
    "tags": [

    ]
  }
}

I am trying to look for a way to manage this json config in github and when there is a change in the version of app_version, I update the json file in github and update the version to 1.0.1 and run a command like knife node edit -c <json file from github> app-node-01 the command will go over the json file and update the node in chef? is this possible?

I tried the command in my local but it opened the VI editor for me to edit.

I dont want to do manual edits as I am trying to look for a way to manage this also in github just like any other chef artifact (data bags, environment files, cookbooks etc)


Solution

  • Like with other Chef artifacts, nodes can also be updated from file using the from file argument.

    Instead of knife node edit, you need to run:

    knife node from file PATH_TO_JSON_FILE