Permalink
Browse files

Create solo.rb from a template

Require at least fabric 1.0.2
  • Loading branch information...
1 parent b53229d commit 370b3c65cb2160642ca115c443febe3adb093ddc @tobami tobami committed Jun 27, 2011
Showing with 26 additions and 18 deletions.
  1. +1 −0 MANIFEST.in
  2. +4 −2 littlechef/chef.py
  3. +19 −14 littlechef/solo.py
  4. +2 −2 setup.py
View
@@ -2,3 +2,4 @@ include README.md
include LICENSE
include NOTICE
include littlechef/data_bags_patch.rb
+include littlechef/solo.rb
View
@@ -28,6 +28,9 @@
from littlechef import solo
from littlechef.settings import node_work_path, cookbook_paths
+# Path to local patch
+basedir = os.path.abspath(os.path.dirname(__file__).replace('\\', '/'))
+
def _save_config(node):
"""Saves node configuration
@@ -136,8 +139,6 @@ def _add_data_bag_patch():
lib_path = os.path.join(
node_work_path, cookbook_paths[0], 'data_bag_lib', 'libraries')
sudo('mkdir -p {0}'.format(lib_path))
- # Path to local patch
- basedir = os.path.abspath(os.path.dirname(__file__).replace('\\', '/'))
# Create remote data bags patch
put(os.path.join(basedir, 'data_bags_patch.rb'),
os.path.join(lib_path, 'data_bags.rb'), use_sudo=True)
@@ -155,6 +156,7 @@ def _configure_node(configfile):
os.remove(configfile)
# Always configure Chef Solo
solo.configure()
+
print "\n== Cooking ==\n"
with settings(hide('warnings', 'running'), warn_only=True):
output = sudo(
View
@@ -13,14 +13,19 @@
#limitations under the License.
#
"""Chef Solo deployment"""
+import os
+
from fabric.api import *
-from fabric.contrib.files import append, exists
+from fabric.contrib.files import append, exists, upload_template
from fabric.utils import abort
from littlechef.lib import credentials
from littlechef.settings import node_work_path, cookbook_paths
+# Path to local patch
+basedir = os.path.abspath(os.path.dirname(__file__).replace('\\', '/'))
+
def install(distro_type, distro, gems, version):
with credentials():
if distro_type == "debian":
@@ -42,23 +47,23 @@ def install(distro_type, distro, gems, version):
def configure():
"""Deploy chef-solo specific files"""
with credentials():
- sudo('mkdir -p {0}/cache'.format(node_work_path))
- sudo('umask 0377; touch solo.rb')
- text = ""
- text += 'file_cache_path "{0}/cache"'.format(node_work_path)
- text += "\n"
+ # Ensure that config directories exist
+ cache_dir = "{0}/cache".format(node_work_path)
+ if not exists(cache_dir):
+ sudo('mkdir -p {0}'.format(cache_dir))
+ if not exists('/etc/chef'):
+ sudo('mkdir -p /etc/chef')
+ # Set parameters and upload solo.rb template
reversed_cookbook_paths = cookbook_paths[:]
reversed_cookbook_paths.reverse()
- cookbook_paths_line = 'cookbook_path [{0}]'.format(', '.join(
+ cookbook_paths_list = '[{0}]'.format(', '.join(
['"{0}/{1}"'.format(node_work_path, x) \
for x in reversed_cookbook_paths]))
- text += cookbook_paths_line + "\n"
- text += cookbook_paths_line + "\n"
- text += 'role_path "{0}/roles"'.format(node_work_path) + "\n"
- text += 'data_bag_path "{0}/data_bags"'.format(node_work_path) + "\n"
- append('solo.rb', text, use_sudo=True)
- sudo('mkdir -p /etc/chef')
- sudo('mv solo.rb /etc/chef/')
+ data = {'node_work_path': node_work_path,
+ 'cookbook_paths_list': cookbook_paths_list}
+ upload_template(os.path.join(basedir, 'solo.rb'), '/etc/chef/',
+ context=data, use_sudo=True, mode=0400)
+ sudo('chown root:root {0}'.format('/etc/chef/solo.rb'))
def check_distro():
View
@@ -19,9 +19,9 @@
url="http://github.com/tobami/littlechef",
download_url="http://github.com/tobami/littlechef/archives/master",
keywords=["chef", "devops"],
- install_requires=['fabric>=1.0.1', 'simplejson'],
+ install_requires=['fabric>=1.0.2', 'simplejson'],
packages=['littlechef'],
- package_data={'littlechef': ['data_bags_patch.rb']},
+ package_data={'littlechef': ['data_bags_patch.rb', 'solo.rb']},
scripts=['cook'],
test_suite='nose.collector',
classifiers=[

0 comments on commit 370b3c6

Please sign in to comment.