Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a patch for Chef::Environment to set node.chef_environment to some

meaningful value.
This value is set to the 'environment' attribute of the node on which the
configuration is done. If no such attribute is found it's set to '_default'.
  • Loading branch information...
commit d7a227f6c751ca31ffa90722995a8a89889bb851 1 parent 249af24
@thekorn thekorn authored
View
1  MANIFEST.in
@@ -4,3 +4,4 @@ include NOTICE
include littlechef/search.rb
include littlechef/solo.rb
include littlechef/parser.rb
+include littlechef/environment.rb
View
20 littlechef/chef.py
@@ -67,9 +67,9 @@ def sync_node(node):
existent.
"""
with lib.credentials():
+ current_node = _synchronize_node()
# Always configure Chef Solo
- solo.configure()
- _synchronize_node()
+ solo.configure(current_node)
# Everything was configured alright, so save the node configuration
filepath = save_config(node, _get_ipaddress(node))
_configure_node(filepath)
@@ -79,8 +79,11 @@ def _synchronize_node():
"""Performs the Synchronize step of a Chef run:
Uploads all cookbooks, all roles and all databags to a node and add the
patch for data bags
+
+ Returns the node object of the node which is about to be configured, or None
+ if this node object cannot be found.
"""
- _build_node_data_bag()
+ current_node = _build_node_data_bag()
print "Synchronizing cookbooks, roles and data bags..."
rsync_project(
node_work_path, './',
@@ -95,6 +98,7 @@ def _synchronize_node():
)
_remove_node_data_bag()
_add_search_patch()
+ return current_node
def build_dct(dic, keys, value):
@@ -178,8 +182,11 @@ def _build_node_data_bag():
'id': It adds data bag 'id' using the filename minus the .json extension
'name': same as 'id'
all attributes found in nodes/<item>.json file
-
+
+ Returns the node object of the node which is about to be configured, or None
+ if this node object cannot be found.
"""
+ current_node = None
nodes = lib.get_nodes()
node_data_bag_path = os.path.join('data_bags', 'node')
_remove_node_data_bag()
@@ -207,6 +214,9 @@ def _build_node_data_bag():
with open(os.path.join(
'data_bags', 'node', node['id'] + '.json'), 'w') as f:
f.write(json.dumps(node))
+ if node['name'] == env.host_string:
+ current_node = node
+ return current_node
def _remove_node_data_bag():
@@ -226,7 +236,7 @@ def _add_search_patch():
with hide('running', 'stdout'):
sudo('mkdir -p {0}'.format(lib_path))
# Create remote data bags patch
- for filename in ('search.rb', 'parser.rb'):
+ for filename in ('search.rb', 'parser.rb', 'environment.rb'):
put(os.path.join(basedir, filename),
os.path.join(lib_path, filename), use_sudo=True)
View
32 littlechef/environment.rb
@@ -0,0 +1,32 @@
+#
+# Copyright 2011, edelight GmbH
+#
+# Authors:
+# Markus Korn <markus.korn@edelight.de>
+#
+# 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.
+#
+
+if Chef::Config[:solo]
+
+ class Chef
+ class Environment
+ def self.load(name)
+ Chef::Log.debug("Successfully set 'node.chef_environment' to '#{name}'")
+ Chef::Log.info("Cannot load environment '#{name}', operation not supported by chef-solo")
+ return nil
+ end
+ end
+ end
+
+end
View
10 littlechef/solo.py
@@ -46,8 +46,9 @@ def install(distro_type, distro, gems, version):
abort('wrong distro type: {0}'.format(distro_type))
-def configure():
+def configure(current_node=None):
"""Deploy chef-solo specific files"""
+ current_node = current_node or {}
with credentials():
# Ensure that config directories exist
cache_dir = "{0}/cache".format(node_work_path)
@@ -61,8 +62,11 @@ def configure():
cookbook_paths_list = '[{0}]'.format(', '.join(
['"{0}/{1}"'.format(node_work_path, x) \
for x in reversed_cookbook_paths]))
- data = {'node_work_path': node_work_path,
- 'cookbook_paths_list': cookbook_paths_list}
+ data = {
+ 'node_work_path': node_work_path,
+ 'cookbook_paths_list': cookbook_paths_list,
+ 'environment': current_node.get('environment', '_default')
+ }
with hide('running', 'stdout'):
upload_template(os.path.join(BASEDIR, 'solo.rb'), '/etc/chef/',
context=data, use_sudo=True, mode=0400)
View
1  littlechef/solo.rb
@@ -2,3 +2,4 @@
cookbook_path %(cookbook_paths_list)s
role_path "%(node_work_path)s/roles"
data_bag_path "%(node_work_path)s/data_bags"
+environment "%(environment)s"
View
2  setup.py
@@ -22,7 +22,7 @@
install_requires=['fabric>=1.0.2', 'simplejson'],
packages=['littlechef'],
package_data={
- 'littlechef': ['search.rb', 'solo.rb', 'parser.rb']
+ 'littlechef': ['search.rb', 'solo.rb', 'parser.rb', 'environment.rb']
},
scripts=['cook'],
test_suite='nose.collector',
Please sign in to comment.
Something went wrong with that request. Please try again.