def sync_node(node): """Buils, synchronizes and configures a node""" cookbooks = _build_node(node) with lib.credentials(): _synchronize_node(cookbooks) # Everything was configured alright, so save the node configuration filepath = _save_config(node) _configure_node(filepath)
def install(distro_type, distro, gems): with credentials(): if distro_type == "debian": if gems == "yes": _gem_apt_install() else: _apt_install(distro) elif distro_type == "rpm": if gems == "yes": _gem_rpm_install() else: _rpm_install() elif distro_type == "gentoo": _emerge_install() else: abort('wrong distro type: {0}'.format(distro_type))
def configure(): """Deploy chef-solo specific files""" with credentials(): sudo('mkdir -p {0}'.format(littlechef.node_work_path)) sudo('mkdir -p {0}/cache'.format(littlechef.node_work_path)) sudo('umask 0377; touch solo.rb') append('solo.rb', 'file_cache_path "{0}/cache"'.format( littlechef.node_work_path), use_sudo=True) reversed_cookbook_paths = littlechef.cookbook_paths[:] reversed_cookbook_paths.reverse() cookbook_paths_line = 'cookbook_path [{0}]'.format(', '.join( ['''"{0}/{1}"'''.format(littlechef.node_work_path, x) \ for x in reversed_cookbook_paths])) append('solo.rb', cookbook_paths_line, use_sudo=True) append('solo.rb', 'role_path "{0}/roles"'.format( littlechef.node_work_path), use_sudo=True) sudo('mkdir -p /etc/chef') sudo('mv solo.rb /etc/chef/')
def check_distro(): """Check that the given distro is supported and return the distro type""" debian_distros = ['sid', 'squeeze', 'lenny'] ubuntu_distros = ['maverick', 'lucid', 'karmic', 'jaunty', 'hardy'] rpm_distros = ['centos', 'rhel', 'sl'] with credentials( hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True): output = sudo('cat /etc/issue') if 'Debian GNU/Linux 5.0' in output: distro = "lenny" distro_type = "debian" elif 'Debian GNU/Linux 6.0' in output: distro = "squeeze" distro_type = "debian" elif 'Ubuntu' in output: distro = sudo('lsb_release -c').split('\t')[-1] distro_type = "debian" elif 'CentOS' in output: distro = "CentOS" distro_type = "rpm" elif 'Red Hat Enterprise Linux' in output: distro = "Red Hat" distro_type = "rpm" elif 'Scientific Linux SL' in output: distro = "Scientific Linux" distro_type = "rpm" elif 'This is \\n.\\O (\\s \\m \\r) \\t' in output: distro = "Gentoo" distro_type = "gentoo" else: print "Currently supported distros are:" print " Debian: " + ", ".join(debian_distros) print " Ubuntu: " + ", ".join(ubuntu_distros) print " RHEL: " + ", ".join(rpm_distros) print " Gentoo" abort("Unsupported distro " + run('cat /etc/issue')) return distro_type, distro