From d16068abe5493056959dbf62142d42fc24e6b380 Mon Sep 17 00:00:00 2001 From: Miquel Torres Date: Fri, 21 Nov 2014 16:33:01 +0100 Subject: [PATCH 1/2] Print node header when configuring Chef Solo --- littlechef/chef.py | 4 +++- littlechef/runner.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/littlechef/chef.py b/littlechef/chef.py index a192cdf..32c510e 100644 --- a/littlechef/chef.py +++ b/littlechef/chef.py @@ -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 diff --git a/littlechef/runner.py b/littlechef/runner.py index 5960091..ea95ee0 100644 --- a/littlechef/runner.py +++ b/littlechef/runner.py @@ -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) @@ -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__: From 62b1395276fa3771e356f045c63a84dc07435f50 Mon Sep 17 00:00:00 2001 From: Miquel Torres Date: Fri, 21 Nov 2014 16:33:13 +0100 Subject: [PATCH 2/2] Fix indentation --- littlechef/solo.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/littlechef/solo.py b/littlechef/solo.py index 612915a..b409ec0 100644 --- a/littlechef/solo.py +++ b/littlechef/solo.py @@ -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, @@ -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 " @@ -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'): @@ -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"