This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fabfile.py
executable file
·65 lines (51 loc) · 2 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from os.path import dirname, abspath
from StringIO import StringIO
from fabric.api import env, sudo, cd, put, task
env.chef_executable = '/var/lib/gems/1.8/bin/chef-solo'
env.project_dir = dirname(abspath(__file__))
env.site_configs = "%s/site_configs" % (env.project_dir, )
env.cookbooks_path = "%s/cookbooks" % (env.project_dir, )
env.remote_project_dir = '/var/chef'
env.remote_site_configs = "%s/chef_recipes/site_configs/" % (env.remote_project_dir)
env.remote_cookbooks_path = "%s/chef_recipes/cookbooks" % (env.remote_project_dir, )
# Undocumented feature to remove the prefix from the output.
env.output_prefix = False
@task
def install_chef():
sudo('apt-get -y update', pty=True)
sudo('apt-get -y -q install libopenssl-ruby')
sudo('apt-get -y -q install git-core rubygems ruby ruby-dev', pty=True)
sudo('if ! gem list | grep chef; then gem install chef --no-ri --no-rdoc; fi', pty=True)
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)
@task
def sync_config():
put(env.project_dir, env.remote_project_dir)
def _update_site(site):
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=False)
@task
def update_all_sites():
import os
sync_config()
for site in [f for f in os.listdir(env.site_configs) if f.endswith('.json')]:
print "-- Updating", site
_update_site(site)
print "-- Updated", site
@task
def update_site(site):
import os
sync_config()
if site in os.listdir(env.site_configs):
_update_site(site)
@task
def sites():
import os
for site in os.listdir(env.site_configs):
print '--', site