Skip to content
kenn edited this page Mar 24, 2013 · 10 revisions

Using Sunzi is a baby-step progress toward fully automated configuration management. To some people, that's exactly what is needed.

If you manually setup servers by hand and are scared of heavyweight solutions like Chef or Puppet, you'll find Sunzi very comfortable, as there's nothing new you have to learn - it's just shell script.

Take a look at some real code. This is a valid Sunzi script - you can actually deploy this code on your Ubuntu server.

#!/bin/bash

# Load base utility functions like sunzi.mute() and sunzi.install()
source recipes/sunzi.sh

# Update installed packages
sunzi.mute "aptitude update"
sunzi.mute "aptitude -y safe-upgrade"

# Install packages
sunzi.install "git-core ntp curl"

What does sunzi.mute and sunzi.install do?

sunzi.mute just suppresses stdout and stderr of a command, then pass the exit status - it is useful when you don't want verbose output of the command, so you won't miss what's really important.

sunzi.install is a smart wrapper to aptitude install or yum install, which returns true only when the specified packages are newly installed. Using this, you can tweak a config file after installation, in an idempotent way.

# Install sysstat, then enable it if this is a new install.
if sunzi.install "sysstat"; then
  sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
  /etc/init.d/sysstat restart
fi
Clone this wiki locally