kapale
kapale

Reputation: 535

How do I bootstrap a node with individual attributes

I'm trying to solve the following task with chef (not solo):

I need webserver in different configurations. The difference are only the configuration files e.g. for varnish, php, nginx, ...

Right now I'm using a special cookbook for each webserver configuration.

I'm wondering if and how I can use e.g. json_attrib while bootstraping a node to set an attribute and use this in the recipe to define which configuration file has to be choosen.

Similar like scripts are chosen depending on the operating system, but I want to set this while bootstraping the node.

Upvotes: 0

Views: 503

Answers (1)

Mark O'Connor
Mark O'Connor

Reputation: 77961

Create an environment for each web server app instance:

knife environment create app1 --description "First application"
knife environment create app2 --description "Second application"
knife environment create app3 --description "Third application"

In each environment you can set the attribute values that should override the cookbook defaults:

{
  "name": "app1",
  "description": "First application",
  "override_attributes": {
    "mycookbook": {
      "att1": "one",
      "att2": "two"
    }
  }
}

When bootstrapping your new nodes you chose which environment should be applied:

knife bootstrap server1 --run-list "recipe[mycookbook]" -E app1
knife bootstrap server2 --run-list "recipe[mycookbook]" -E app2
knife bootstrap server3 --run-list "recipe[mycookbook]" -E app3

Upvotes: 1

Related Questions