Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow provide a chef_binary_path from configuration file #246

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build
dist
littlechef.egg-info
.coverage
tags
.eggs
.ropeproject
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.7
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include README.md
include LICENSE
include NOTICE
include littlechef/solo.rb
include littlechef/solo.rb.j2
include littlechef/environment.rb
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
```

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion littlechef/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.. _Chef: http://wiki.opscode.com/display/chef/Home

"""
__version__ = "1.7.4"
__version__ = "1.8.0"
__author__ = "Miquel Torres <[email protected]>"

__cooking__ = False
Expand All @@ -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']
Expand Down
17 changes: 14 additions & 3 deletions littlechef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('\\', '/'))

Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions littlechef/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions littlechef/solo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Copyright 2010-2014 Miquel Torres <[email protected]>
#Copyright 2010-2015 Miquel Torres <[email protected]>
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand All @@ -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))
Expand All @@ -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 {}
Expand Down
5 changes: 3 additions & 2 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
"""LittleChef's setup.py"""
try:
from setuptools import setup
Expand All @@ -16,8 +17,8 @@
description="Cook with Chef without a Chef Server",
author="Miquel Torres",
author_email="[email protected]",
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'],
Expand Down
2 changes: 2 additions & 0 deletions tests/littlechef.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ user = testuser
password = testpass
keypair-file =

[system]

[sync-packages]
dest-dir = /srv/repos
local-dir = ./repos
1 change: 1 addition & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down