chef environment

Chef Environment

An environment is a way to map an organization real-life workflow to what can be configured and managed using the chef server, Apply different cookbook versions to specific environment Define environment level attributes Environments allow sharing of cookbooks within an organization

Creating chef Environment

Environment information can be stored in json file or .rb files, Environment will be located in chef-repo/environments

Example dev.rb

name “dev”

description “Development environment”

cookbook “security”,”=0.1.0”

cookbook”motd”,”=0.2.0”

override_attributes({

“author” =>{

“name” => true

}

})

Environment Attributes

Two types of attribute precedence can be set on the environment level

*Default a default attribute defined in the environment will take precedence over a default attribute defined in a cookbook attribute file.

*Override has higher precedence than the default, force_default, and norm

Create and configure Environment

Create a directory for environments and create a ruby file for the environment (development) as shown below:

#mkdir environments

#ls

cookbooks data_bags environments README.md roles

#cd environments/

#cat environment

name "dev"

description "This is the development environment" 

cookbook "apache", "= 0.1.5" 

override_attributes({

"author" => {

"name" => "my new auther name"

}

})

Command to verify all environments,

# knife environment list -w

_default: https://chefserver.zippyops.com/organizations/zcs/environments/_default

Current one API environment is available. Now we can create our new environment,

# knife environment from file dev.rb 

Updated Environment dev

Now go to the chef server console, click on “Policy” and then check the environment option,

There to be added dev environment. all the nodes are added default environment


This is to be change dev environment, go back to my NODE machine and add the environment info into the file client.rb as follows:

#cd /etc/chef/

#ls

chef_guid client.pem client.rb first-boot.json trusted_certs

#cat client.rb

chef_server_url "https://chefserver.zippyops.com/organizations/zcs-org"

validation_client_name "training-org-validator"

log_location STDOUT

node_name "chefcentos.zippyops.com"

trusted_certs_dir "/etc/chef/trusted_certs"

environment "dev"

Now run the chef-client on node

# chef-client

Starting Chef Client, version 14.8.12

resolving cookbooks for run list: ["apache", "localuser", "localuser::groups", "user"]

System Info:

------------

chef_version=14.8.12

platform=centos

platform_version=7.5.1804

ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]

program_name=/usr/bin/chef-client

executable=/opt/chef/bin/chef-client

Running handlers:

[2018-12-14T20:07:04+05:30] ERROR: Running exception handlers

Running handlers complete

[2018-12-14T20:07:04+05:30] ERROR: Exception handlers complete

Chef Client failed. 0 resources updated in 04 seconds

[2018-12-14T20:07:04+05:30] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out

[2018-12-14T20:07:04+05:30] FATAL: Please provide the contents of the stacktrace.out file if you 

file a bug report

[2018-12-14T20:07:04+05:30] FATAL: Net::HTTPServerException: 412 "Precondition Failed"


Error in our cookbook because we are apache 0.1.0 version , but in our environment, we have added apache 0.1.5 this is not available.

Go back to the chef-server console and refresh our page, environment has been changed to dev.

Recent Comments

No comments

Leave a Comment