Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created May 3, 2011 14:26
Show Gist options
  • Save jtimberman/953420 to your computer and use it in GitHub Desktop.
Save jtimberman/953420 to your computer and use it in GitHub Desktop.
switch nodes from environment roles to Chef 0.10 environments
# Author:: Joshua Timberman (<[email protected]>)
#
# Copyright 2011, Joshua Timberman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# This knife script simply switches nodes in the Chef Server from using
# environment roles (production, staging, etc) to Chef 0.10's Environments.
#
# It was tested in a small infrastructure (5 nodes) on the Opscode Platform.
#
# Set the shell environment variable CHEF_ENV to the desired environment to
# modify nodes, then run the script with knife. If an environment is not
# specified, 'testing' will be used.
#
# % export CHEF_ENV=staging
# % knife exec node_env.rb
env = ENV['CHEF_ENV'] || 'testing'
nodes.transform("app_environment:#{env}") do |n|
puts "Setting Chef Environment of #{n.name} to #{env}"
n.chef_environment("#{env}")
n.run_list.remove("role[#{env}]")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment