Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
An idempotent, DSL-ish library for configuring servers
Ruby
Branch: master
Pull request Compare This branch is 9 commits ahead of tiptapinc:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
LICENSE
README.md
example-postgresql.rb

README.md

MakeItSo is a DSLish library of methods with the following guarantees†:

  • They are idempotent
  • They abort if there are errors
  • They set changed? when they change anything (global state)
  • They return true if they change anything, false if they don't (local state)
  • They (mostly) make dated backups if files change, log details of the change, and report a summary to stdout

† You're right - I can't really call it a guarantee without unit tests. Since you brought this up, you should be the one to write them. RSpec preferred.

Quick example

make = MakeItSo.new
make.dns_entry("ns.example.com", "1.2.3.4", "A")
  #=> true
make.changed?
  #=> true
make.dns_entry("ns.example.com", "1.2.3.4", "A")
  #=> false
make.reset
make.dns_entry("ns.example.com", "1.2.3.4", "A")
  #=> false
make.changed?
  #=> false

General functionality

make.sure_im_root

# Line-by-line editing
make.line_present("#{CONF_DIR}/pg_hba.conf", "host\tall\tubuntu\t10.0.0.0/8\tmd5")
make.line_not_present("#{CONF_DIR}/postgresql.conf", /^#listen_addresses = 'localhost'.*$/)
make.line_present_iff("/etc/apache2/envvars", line, RAILS_ENV == 'production')

# Understands 'key=value' files natively, detecting shell-style (no spaces) or everything-else-style
make.config("/etc/apache2/envvars", { 'PATH' => "/usr/local/rvm", 'RAILS_ENV' => "production"})

# File creation, removal, installation from a dir that mirrors your filesystem layout

 lines = [
  "export RAILS_ENV=#{environment}",
  "export RUBY_GC_MALLOC_LIMIT=59000000",
  "export PGHOST=#{pghost}",
]
make.file_exactly("/etc/profile.d/tiptap_env.sh", lines)

make.files_not_present(
    "/etc/update-motd.d/10-help-text",
    "/etc/update-motd.d/51_update-motd",
    "/etc/update-motd.d/98-cloudguest")
make.files_installed("~/siteconfig", "/etc/logrotate.d")
make.files_installed_iff(files, boolean expression)

# FileUtils-type stuff
make.chmod("~/.ssh", 0700, :no_recurse => true)
make.chown("/var/www", "ubuntu") # does chgrp too, recurses
make.chgrp("/var/www", "www-data")

# Ubuntu stuff
make.apt_installed('apache2')
make.service_disabled('sendmail')

# POSIX stuff

# make.sh is a bit weak right now, but will become a proper logging, error-detecting, shell-safe thingie
make.sh("sudo apt-file update") if @make.changed?

make.host_known("ubuntu@#{gateway_host}") # teach gateway_host's ssh known_hosts about us

Real-world example

See example-postgresql.rb.

TODO

  • Make it a gem
  • Add initializers for output, domain (make = MakeItSo.new)
  • Handle stdout redirects cleanly, perhaps using Process::spawn or executor
  • Be more consistent about logging, maybe verbose mode
Something went wrong with that request. Please try again.