Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json_attributes: true config option to ChefZero provisioner. #280

Merged
merged 1 commit into from
Dec 20, 2013

Conversation

fnichol
Copy link
Contributor

@fnichol fnichol commented Dec 8, 2013

This option allows a user to invoke chef-client without passing the
generated JSON file in the --json-attributes option. That way if you
have a JSON definition of your node (including a run-list), the
chef-client run will depend entirely on what is on the "Chef Server".

For example, let's assume we want a node called "mynode" to be in the
"production" chef environment. Given a .kitchen.yml with the following:


---
driver:
  name: vagrant

provisioner:
  name: chef_zero
  json_attributes: false
  client_rb:
    node_name: mynode

platforms:
  - name: ubuntu-12.04

suites:
  - name: default

and an environment JSON description for our chef environment called
"production" in test/integration/environments/production.json that
looks like:

{
  "name": "production",
  "default_attributes": {
    "myenv_attr": "Good to be in prod"
  }
}

and a node JSON description for our node called "mynode" in
test/integration/nodes/mynode.json that looks like:

{
  "id": "mynode",
  "chef_environment": "production",
  "run_list": [
    "recipe[nginx]"
  ],
  "normal": {
    "some_attr": "hello"
  },
  "automatic": {
    "ipaddress": "192.168.77.77"
  }
}

then the instance will attempt to register with the Chef Zero server as
"mynode" (vs. "default-ubuntu-1204" in this case) and will receive a
run-list of ["recipe[nginx]"] from the server. Additionally the
following node attributes will be setup:

  • node[:some_attr] will be set to "hello"
  • node[:myenv_attr] will be set to "Good to be in prod"
  • node[:ipaddress] will be set to "192.168.77.77"

Note that the node JSON format assumes a Chef 11 serialized format which
Chef Zero will use under the hood. For more details, please read:

http://docs.opscode.com/essentials_node_object.html

This option allows a user to invoke chef-client without passing the
generated JSON file in the `--json-attributes` option. That way if you
have a JSON definition of your node (including a run-list), the
chef-client run will depend entirely on what is on the "Chef Server".

For example, let's assume we want a node called "mynode" to be in the
"production" chef environment. Given a .kitchen.yml with the following:

    ---
    driver:
      name: vagrant

    provisioner:
      name: chef_zero
      json_attributes: false
      client_rb:
        node_name: mynode

    platforms:
      - name: ubuntu-12.04

    suites:
      - name: default

and an environment JSON description for our chef environment called
"production" in `test/integration/environments/production.json` that
looks like:

    {
      "name": "production",
      "default_attributes": {
        "myenv_attr": "Good to be in prod"
      }
    }

and a node JSON description for our node called "mynode" in
`test/integration/nodes/mynode.json` that looks like:

    {
      "id": "mynode",
      "chef_environment": "production",
      "run_list": [
        "recipe[nginx]"
      ],
      "normal": {
        "some_attr": "hello"
      },
      "automatic": {
        "ipaddress": "192.168.77.77"
      }
    }

then the instance will attempt to register with the Chef Zero server as
"mynode" (vs. "default-ubuntu-1204" in this case) and will receive a
run-list of `["recipe[nginx]"]` from the server. Additionally the
following node attributes will be setup:

* `node[:some_attr]` will be set to `"hello"`
* `node[:myenv_attr]` will be set to `"Good to be in prod"`
* `node[:ipaddress]` will be set to `"192.168.77.77"`

Note that the node JSON format assumes a Chef 11 serialized format which
Chef Zero will use under the hood. For more details, please read:

http://docs.opscode.com/essentials_node_object.html
@spheromak
Copy link

ah this is great ⭐

@fnichol
Copy link
Contributor Author

fnichol commented Dec 20, 2013

How did I forget about you, oh cool feature? Let's get you merged in, shall we?

fnichol added a commit that referenced this pull request Dec 20, 2013
Add `json_attributes: true` config option to ChefZero provisioner.
@fnichol fnichol merged commit 9e28a67 into master Dec 20, 2013
@fnichol fnichol deleted the chef-zero-skip-json-attributes branch December 20, 2013 07:44
@test-kitchen test-kitchen locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants