Search code examples
rubychef-infrachef-recipechef-solo

chef-solo/chef-client local mode doesn't accept attribute override in a json


I have a cookbook and roles.son and environment.json file available. I run them through both chef-solo and chef-client -z (local mode).

Both give the ability to add -j flag to pass the roles.json but doesn't provide any easy way of attribute overriding using environment.json. I am not using a server so not pushing it any where.

Am I missing something ?

I have something like this :

cookbooks  environment.json  file.txt  local-mode-cache  nodes  roles.json

and I'm running the following

1 : chef-client local mode with client.rb:

log_level               :info
log_location            "/var/log/chef/client.log"
node_name       "ip-10-201-38-78"
cookbook_path           "/tmp/cookbooks/"
json_attribs        "/tmp/roles.json" 

chef-client -z -c client.rb -j roles.json

  1. chef-solo -c client.rb -j roles.json

Solution

  • The -j is not used to specify the role information, see:

    It can be used to specify node attributes, but would have a different format compared to the roles file.

    Update

    I suspect you don't need a role at all.

    Here's an example of how to specify both node attributes and the run-list in the JSON file passed to chef client:

    sudo chef-client -z -j node.json
    

    The cookbook dependencies are of course located in a "cookbooks" subdir

    ├── node.json
    ├── cookbooks
        ├── apt ..
        ├── build-essential ..
        ├── chef_handler ..
        ├── compat_resource ..
        ├── homebrew ..
        ├── java ..
        ├── mingw ..
        ├── seven_zip ..
        └── windows ..
    

    node.json

    {
      "java": {
        "jdk_version":8,
        "install_flavor":"oracle",
        "oracle": {
          "accept_oracle_download_terms":true
        }
      },
      "run_list":[
        "recipe[apt]",
        "recipe[java]"
      ]
    }