Performing a No-Op with chef-client using JSON

Featured image for sharing metadata for article

There could be a case where you may want to perform a chef-client run so it doesn't actually change any resources.

I previously wanted to do this, but encountered a bit of a funny gotcha, so decided to document it.

Let us assume that our regular cookbook JSON configuration is:

{
  "java": {
    "jdk_version": 7
  },
  "run_list": [
    "java"
  ]
}

Which performs the following chef-client run:

$ chef-client -j full-run.json
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: ["java"]
Synchronizing Cookbooks:
  - java (3.2.0)
  - windows (5.2.3)
  - homebrew (5.0.8)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 7 resources
Recipe: java::notify
  * log[jdk-version-changed] action nothing (skipped due to action :nothing)
Recipe: java::openjdk
  * apt_repository[openjdk-r-ppa] action add
    ...
Running handlers:
Running handlers complete
Chef Client finished, 5/12 resources updated in 04 minutes 04 seconds

Expected Solution

The no-op configuration I tried at first was, as simple as I could think, an empty JSON object:

{}

But unfortunately that doesn't quite work:

$ chef-client -j noop.json
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: ["java"]
Synchronizing Cookbooks:
  - java (3.2.0)
  - windows (5.2.3)
  - homebrew (5.0.8)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 7 resources
Recipe: java::notify
  * log[jdk-version-changed] action nothing (skipped due to action :nothing)
Recipe: java::openjdk
  * apt_repository[openjdk-r-ppa] action add
    ...
Recipe: java::set_java_home
  * directory[/etc/profile.d] action create (up to date)
  * template[/etc/profile.d/jdk.sh] action create (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 0/11 resources updated in 06 seconds

Actual Solution

Instead, we need to have an empty JSON object with a zero-length run_list:

{
  "run_list": []
}

This then gives us a true no-op:

$ chef-client -j real-noop.json
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 0 resources

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 01 seconds

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #chef.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.