diff --git a/.gitignore b/.gitignore index 6988b7a..2c0d08b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build dist littlechef.egg-info .coverage +tags +.eggs +.ropeproject diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..1f7da99 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +2.7.7 diff --git a/CHANGELOG b/CHANGELOG index 349b002..822d341 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,13 @@ LittleChef Changelog ==================== +Version 1.8.0 March 30, 2015 +---------------------------------------- +New features: +* #232: Option for colorless output +* #228: Omnibus as default install method. Defaults to Chef 11 +* #212: http proxy + Version 1.7.2 May 23, 2014 ---------------------------------------- diff --git a/MANIFEST.in b/MANIFEST.in index ba3b3bd..d478861 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include README.md include LICENSE include NOTICE -include littlechef/solo.rb +include littlechef/solo.rb.j2 include littlechef/environment.rb diff --git a/README.md b/README.md index 6fb89d1..6fb8224 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ kitchen to: node_work_path = /tmp/chef-solo ``` -If you're using encrypted data bags you can specify a path for the encrypted_data_bag_secret file: +You can use encrypted data bags. [Create secret keys](https://docs.chef.io/chef/essentials_data_bags.html#secret-keys), Use [knife-solo_data_bag](https://github.com/thbishop/knife-solo_data_bag) Gem to create encrypted data bags, and specify a path for the encrypted_data_bag_secret file: ```ini [userinfo] @@ -203,8 +203,15 @@ This will put the encrypted_data_bag_secret in `/etc/chef/encrypted_data_bag_sec Chef-solo will automatically use it wherever you use `Chef::EncryptedDataBagItem.load` in your recipes. It will also remove the `/etc/chef/encrypted_data_bag_secret` file from the node at the end of the run. +If you are not comfortable about leaving data bags in the remote node, which will leak sensitive information, you can tell littlechef to delete them all at the end of the run: + ```ini -[kitchen] +[userinfo] +remove_data_bags=true +``` + +```ini +[userinfo] autodeploy_chef=true ``` @@ -385,19 +392,19 @@ If you find bugs please report it on [https://github.com/tobami/littlechef/issue Happy cooking! [Chef]: http://www.getchef.com/chef/ - [Nodes]: http://docs.opscode.com/essentials_node_object.html - [Cookbooks]: http://docs.opscode.com/essentials_cookbooks.html - [Environments]: http://docs.opscode.com/essentials_environments.html - [Roles]: http://docs.opscode.com/essentials_roles.html - [Data Bags]: http://docs.opscode.com/essentials_data_bags.html - [chef-solo-search library]: http://community.opscode.com/cookbooks/chef-solo-search - [Chef attribute preference rules]: http://docs.opscode.com/essentials_cookbook_attribute_files.html#attribute-precedence - [automatic attributes]: http://docs.opscode.com/essentials_cookbook_recipes.html#Recipes-CommonAutomaticAttributes + [Nodes]: http://docs.chef.io/nodes.html + [Cookbooks]: http://docs.chef.io/cookbooks.html + [Environments]: http://docs.chef.io/environments.html + [Roles]: http://docs.chef.io/roles.html + [Data Bags]: http://docs.chef.io/data_bags.html + [chef-solo-search library]: https://supermarket.chef.io/cookbooks/chef-solo-search + [Chef attribute preference rules]: https://docs.chef.io/attributes.html#attribute-precedence + [automatic attributes]: http://docs.chef.io/recipes.html [Kitchen]: https://github.com/edelight/kitchen/ - [search wiki page]: http://docs.opscode.com/essentials_search.html#query-syntax + [search wiki page]: http://docs.chef.io/chef_search.html [getchef]: https://www.chef.io/download-chef-client/ - [Opscode repository]: http://docs.opscode.com/install_server.html#Installation-InstallingChefClientandChefSolo - [Whyrun]: https://wiki.opscode.com/display/chef/Whyrun+Testing + [Opscode repository]: https://docs.chef.io/install_server.html#Installation-InstallingChefClientandChefSolo + [Whyrun]: https://docs.chef.io/debug.html [Automated Deployments with LittleChef]: http://sysadvent.blogspot.com/2010/12/day-9-automated-deployments-with.html [discussion group]: http://groups.google.com/group/littlechef [https://github.com/tobami/littlechef/issues]: https://github.com/tobami/littlechef/issues diff --git a/littlechef/__init__.py b/littlechef/__init__.py index e58c314..d960f0d 100644 --- a/littlechef/__init__.py +++ b/littlechef/__init__.py @@ -14,7 +14,7 @@ .. _Chef: http://wiki.opscode.com/display/chef/Home """ -__version__ = "1.7.4" +__version__ = "1.8.0" __author__ = "Miquel Torres " __cooking__ = False @@ -30,6 +30,7 @@ concurrency = False include_guests = False no_color = False +chef_binary_path = None node_work_path = "/tmp/chef-solo" cookbook_paths = ['site-cookbooks', 'cookbooks'] diff --git a/littlechef/chef.py b/littlechef/chef.py index 2c32638..561c178 100644 --- a/littlechef/chef.py +++ b/littlechef/chef.py @@ -26,9 +26,11 @@ from fabric.utils import abort from fabric.contrib.project import rsync_project +import littlechef from littlechef import cookbook_paths, whyrun, lib, solo, colors from littlechef import LOGFILE, enable_logs as ENABLE_LOGS + # Path to local patch basedir = os.path.abspath(os.path.dirname(__file__).replace('\\', '/')) @@ -58,9 +60,10 @@ def _get_ipaddress(node): Returns True if ipaddress is added, False otherwise """ + ohai_exec = '{chef_path}/ohai -l warn ipaddress'.format(chef_path = littlechef.chef_binary_path) if "ipaddress" not in node: with settings(hide('stdout'), warn_only=True): - output = sudo('ohai -l warn ipaddress') + output = sudo(ohai_exec) if output.succeeded: try: node['ipaddress'] = json.loads(output)[0] @@ -76,7 +79,8 @@ def chef_test(): False otherwise """ - cmd = "chef-solo --version" + + cmd = "{chef_path}/chef-solo --version".format(chef_path = littlechef.chef_binary_path) output = sudo(cmd, warn_only=True, quiet=True) if 'chef-solo: command not found' in output: return False @@ -394,11 +398,18 @@ def _remove_remote_node_data_bag(): if exists(node_data_bag_path): sudo("rm -rf {0}".format(node_data_bag_path)) +def _remove_remote_data_bags(): + """Remove remote data bags, so it won't leak any sensitive information""" + data_bags_path = os.path.join(env.node_work_path, 'data_bags') + if exists(data_bags_path): + sudo("rm -rf {0}".format(data_bags_path)) def _node_cleanup(): if env.loglevel is not "debug": with hide('running', 'stdout'): _remove_remote_node_data_bag() + if env.remove_data_bags: + _remove_remote_data_bags() with settings(warn_only=True): sudo("rm '/etc/chef/node.json'") if env.encrypted_data_bag_secret: @@ -432,7 +443,7 @@ def _configure_node(): with settings(hide('stdout', 'warnings', 'running'), warn_only=True): sudo("mv {0} {0}.1".format(LOGFILE)) # Build chef-solo command - cmd = "RUBYOPT=-Ku chef-solo" + cmd = "RUBYOPT=-Ku {chef_path}/chef-solo".format(chef_path = littlechef.chef_binary_path) if whyrun: cmd += " --why-run" cmd += ' -l {0} -j /etc/chef/node.json'.format(env.loglevel) diff --git a/littlechef/runner.py b/littlechef/runner.py index 7985c64..f3c2730 100644 --- a/littlechef/runner.py +++ b/littlechef/runner.py @@ -86,6 +86,7 @@ def _mkdir(d, content=""): print >> configfh, "encrypted_data_bag_secret = " print >> configfh, "[kitchen]" print >> configfh, "node_work_path = /tmp/chef-solo/" + print >> configfh, '[system]' print "{0} file created...".format(littlechef.CONFIGFILE) @@ -444,6 +445,10 @@ def _readconfig(): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): env.https_proxy = None + try: + env.remove_data_bags = config.get('userinfo', 'remove_data_bags') + except ConfigParser.NoOptionError: + env.remove_data_bags = None # Check for an encrypted_data_bag_secret file and set the env option try: env.encrypted_data_bag_secret = config.get('userinfo', @@ -546,6 +551,12 @@ def _readconfig(): except ConfigParser.NoOptionError: env.autodeploy_chef = None + # set chef binary path if users specify one + try: + littlechef.chef_binary_path = config.get('system', 'chef_binary_path') + except (ConfigParser.NoOptionError, ConfigParser.NoOptionError): + littlechef.chef_binary_path = '/bin' + # Only read config if fix is being used and we are not creating a new kitchen if littlechef.__cooking__: # Called from command line diff --git a/littlechef/solo.py b/littlechef/solo.py index 3168744..1b8e074 100644 --- a/littlechef/solo.py +++ b/littlechef/solo.py @@ -1,4 +1,4 @@ -#Copyright 2010-2014 Miquel Torres +#Copyright 2010-2015 Miquel Torres # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. @@ -14,21 +14,21 @@ # """Chef Solo deployment""" import os -import re from fabric.api import * -from fabric.contrib.files import append, exists, upload_template +from fabric.contrib.files import exists, upload_template from fabric.utils import abort -from littlechef import cookbook_paths, colors +from littlechef import cookbook_paths from littlechef import LOGFILE # Path to local patch BASEDIR = os.path.abspath(os.path.dirname(__file__).replace('\\', '/')) + def install(version): """Install Chef using the omnibus installer""" - url = "https://www.opscode.com/chef/install.sh" + url = "https://www.chef.io/chef/install.sh" with hide('stdout', 'running'): local("""python -c "import urllib; print urllib.urlopen('{0}').read()"' ' > /tmp/install.sh""".format(url)) @@ -38,6 +38,7 @@ def install(version): sudo("""bash /tmp/install.sh -v {0}""".format(version)) sudo('rm /tmp/install.sh') + def configure(current_node=None): """Deploy chef-solo specific files""" current_node = current_node or {} diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 6e0d0cf..2372310 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python """LittleChef's setup.py""" try: from setuptools import setup @@ -16,8 +17,8 @@ description="Cook with Chef without a Chef Server", author="Miquel Torres", author_email="tobami@gmail.com", - url="http://github.com/tobami/littlechef", - download_url="http://github.com/tobami/littlechef/tags", + url="http://github.com/wilddog64/littlechef", + download_url="http://github.com/wilddog64/littlechef/tags", keywords=["chef", "devops", "operations", "sysadmin"], install_requires=['fabric>=1.5.4', 'argparse', 'jinja2>=2.7.3'], packages=['littlechef'], diff --git a/tests/littlechef.cfg b/tests/littlechef.cfg index d7b6d4e..981a782 100644 --- a/tests/littlechef.cfg +++ b/tests/littlechef.cfg @@ -3,6 +3,8 @@ user = testuser password = testpass keypair-file = +[system] + [sync-packages] dest-dir = /srv/repos local-dir = ./repos diff --git a/tests/test_command.py b/tests/test_command.py index f5fe539..9c2dba6 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -261,6 +261,7 @@ def test_new_kitchen_can_list_nodes(self): print >> configfh, "[userinfo]" print >> configfh, "user = testuser" print >> configfh, "password = testpassword" + print >> configfh, "[system]" resp, error = self.execute([fix, 'list_nodes']) self.assertFalse(error)