Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Added support for a chef-solo config gile and reduced some of the out…
Browse files Browse the repository at this point in the history
…put from fabric to aid the signal to noise ratio.
  • Loading branch information
d0ugal committed Sep 13, 2011
1 parent 4c81814 commit e19d711
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
45 changes: 26 additions & 19 deletions fabfile.py
@@ -1,36 +1,43 @@
from os.path import dirname, abspath
from StringIO import StringIO

from fabric.api import env, sudo, cd, put
from fabric.api import env, sudo, cd, put, hide

env.chef_executable = '/var/lib/gems/1.8/bin/chef-solo'

env.project_dir = dirname(abspath(__file__))
env.site_configs = "%s/%s" % (env.project_dir, 'site_configs',)
env.site_configs_remote = "/var/chef/site_configs/"
env.site_configs = "%s/site_configs" % (env.project_dir, )
env.cookbooks_path = "%s/cookbooks" % (env.project_dir, )

env.remote_project_dir = '/var/chef/chef_recipes'
env.remote_site_configs = "%s/site_configs/" % (env.remote_project_dir)
env.remote_cookbooks_path = "%s/cookbooks" % (env.remote_project_dir, )


def install_chef():
sudo('apt-get update', pty=True)
sudo('apt-get install -y libopenssl-ruby')
sudo('apt-get install -y git-core rubygems ruby ruby-dev', pty=True)
sudo('apt-get update -q', pty=True)
sudo('apt-get install -y -q libopenssl-ruby')
sudo('apt-get install -y -q git-core rubygems ruby ruby-dev', pty=True)
sudo('gem install chef --no-ri --no-rdoc', pty=True)
sudo('mkdir -p /var/chef')
sudo('chown %s /var/chef' % (env.user))
sudo('mkdir -p %s' % env.remote_project_dir)
sudo('chown %s %s' % (env.user, env.remote_project_dir))

chef_config = StringIO()
chef_config.write('cookbook_path "%s"\n' % env.remote_cookbooks_path)
put(chef_config, '%s/solo.rb' % env.remote_project_dir, use_sudo=True)

def sync_config():
put(env.project_dir, '/var/chef')


def update():
sync_config()
with cd('/var/chef'):
sudo('%s' % env.chef_executable, pty=True)
def sync_config():
with hide('running',):
put(env.project_dir, env.remote_project_dir)


def _update_site(site):
with cd('/var/chef'):
chef = env.chef_executable
configs = env.site_configs_remote
sudo('%s -j %s%s' % (chef, configs, site), pty=True)
with cd(env.remote_project_dir):
sudo('{chef} -j {configs}{site} -c {proj_dir}/solo.rb'.format(
chef = env.chef_executable, configs = env.remote_site_configs,
site = site, proj_dir = env.remote_project_dir
), pty=True)


def update_all():
Expand Down
2 changes: 1 addition & 1 deletion site_configs/example.json
@@ -1,5 +1,5 @@
{
"run_list": [ "main", "python", "postgres",],
"run_list": [ "main", "python", "postgres"],
"user_name": "new_user",
"user_password": "new_user_password",
"user_group": "user_group",
Expand Down
24 changes: 17 additions & 7 deletions test/runtest.py
Expand Up @@ -10,7 +10,7 @@

from boto.ec2 import EC2Connection, get_region
from boto.exception import EC2ResponseError
from fabric.api import env, settings
from fabric.api import env, settings, run, hide
from fabric.network import disconnect_all
from unipath import Path

Expand Down Expand Up @@ -121,12 +121,22 @@ def test(self, host_string, user, key_pair, key_filename):

with settings(host_string=host_string, key_filename=key_filename, user=user):

print 'OK!'
install_chef()
sync_config()
sites()
update_all()
print "DONE!"
with hide('stdout',):

print 'OK! Started.'

install_chef()
print "1/4 Chef installed."

sync_config()
print "2/4 Config Synced."

sites()
print "3/4 Sites listed."

update_all()
print "4/4 Full update."


def tear_down(self):

Expand Down

0 comments on commit e19d711

Please sign in to comment.