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

Deploy chef header #223

Merged
merged 2 commits into from Nov 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion littlechef/chef.py
Expand Up @@ -70,13 +70,15 @@ def _get_ipaddress(node):
return True
return False


def chef_test():
cmd="chef-solo --version"
cmd = "chef-solo --version"
output = sudo(cmd, warn_only=True, quiet=True)
if 'chef-solo: command not found' in output:
return False
return True


def sync_node(node):
"""Builds, synchronizes and configures a node.
It also injects the ipaddress to the node's config file if not already
Expand Down
3 changes: 2 additions & 1 deletion littlechef/runner.py
Expand Up @@ -175,7 +175,7 @@ def _node_runner():
print "TEST: would now configure {0}".format(env.host_string)
else:
lib.print_header("Configuring {0}".format(env.host_string))
if env.autodeploy_chef and not chef.chef_test():
if env.autodeploy_chef and not chef.chef_test():
deploy_chef(method="omnibus")
chef.sync_node(node)

Expand Down Expand Up @@ -211,6 +211,7 @@ def deploy_chef(gems="no", ask="yes", version="11", distro_type=None,
if not confirm(message):
abort('Aborted by user')

lib.print_header("Configuring Chef Solo on {0}".format(env.host_string))
_configure_fabric_for_platform(platform)

if not __testing__:
Expand Down
22 changes: 13 additions & 9 deletions littlechef/solo.py
Expand Up @@ -94,7 +94,7 @@ def configure(current_node=None):
reversed_cookbook_paths = cookbook_paths[:]
reversed_cookbook_paths.reverse()
cookbook_paths_list = '[{0}]'.format(', '.join(
['"{0}/{1}"'.format(env.node_work_path, x) \
['"{0}/{1}"'.format(env.node_work_path, x)
for x in reversed_cookbook_paths]))
data = {
'node_work_path': env.node_work_path,
Expand All @@ -107,8 +107,8 @@ def configure(current_node=None):
with settings(hide('everything')):
try:
upload_template('solo.rb.j2', '/etc/chef/solo.rb',
context=data, use_sudo=True, backup=False, template_dir=BASEDIR,
use_jinja=True, mode=0400)
context=data, use_sudo=True, backup=False,
template_dir=BASEDIR, use_jinja=True, mode=0400)
except SystemExit:
error = ("Failed to upload '/etc/chef/solo.rb'\nThis "
"can happen when the deployment user does not have a "
Expand Down Expand Up @@ -232,20 +232,24 @@ def _gem_pacman_install():
def _gem_ports_install():
"""Install Chef from gems for FreeBSD"""
with hide('stdout', 'running'):
sudo('grep -q RUBY_VER /etc/make.conf || echo \'RUBY_VER=1.9\' >> /etc/make.conf')
sudo('grep -q RUBY_DEFAULT_VER /etc/make.conf || echo \'RUBY_DEFAULT_VER=1.9\' >> /etc/make.conf')
sudo('grep -q RUBY_VER /etc/make.conf || '
'echo \'RUBY_VER=1.9\' >> /etc/make.conf')
sudo('grep -q RUBY_DEFAULT_VER /etc/make.conf || '
'echo \'RUBY_DEFAULT_VER=1.9\' >> /etc/make.conf')
with show('running'):
sudo('which -s rsync || pkg_add -r rsync')
sudo('which -s perl || pkg_add -r perl')
sudo('which -s m4 || pkg_add -r m4')
sudo('which -s chef || (cd /usr/ports/sysutils/rubygem-chef && make -DBATCH install)')
sudo('which -s chef || '
'(cd /usr/ports/sysutils/rubygem-chef && make -DBATCH install)')


def _omnibus_install(version):
"""Install Chef using the omnibus installer"""
url = "https://www.opscode.com/chef/install.sh"
with hide('stdout', 'running'):
local("""python -c "import urllib; print urllib.urlopen('{0}').read()" > /tmp/install.sh""".format(url))
local("""python -c "import urllib; print urllib.urlopen('{0}').read()"'
' > /tmp/install.sh""".format(url))
put('/tmp/install.sh', '/tmp/install.sh')
print("Downloading and installing Chef {0}...".format(version))
with hide('stdout'):
Expand Down Expand Up @@ -284,8 +288,8 @@ def _apt_install(distro, version, stop_client='yes'):
else:
version = "-" + version
append('opscode.list',
'deb http://apt.opscode.com/ {0}{1} main'.format(distro, version),
use_sudo=True)
'deb http://apt.opscode.com/ {0}{1} main'.format(distro, version),
use_sudo=True)
sudo('mv opscode.list /etc/apt/sources.list.d/')
# Add repository GPG key
gpg_key = "http://apt.opscode.com/packages@opscode.com.gpg.key"
Expand Down