Apply configuration from cloud metadata.
Go to file
Clint Byrum 40f7da49ed Adding MANIFEST.in and fixing .gitreview
Bit-rot from no development going on has led to some problems. The
.gitrview file points at the old named repo. MANIFEST.in is needed to
make sure we have README.md to satisfy setup.cfg using it for the long
description.

Change-Id: I9ba5b2c1eda349b26d24833ebd5cbd5244584311
2013-07-17 01:52:26 -07:00
os_apply_config Add a 'dsn' type for matching sqlalchemy-ish dsns. 2013-06-19 08:05:18 -07:00
.gitignore Rename to os-apply-config. 2013-06-14 15:30:14 +12:00
.gitreview Adding MANIFEST.in and fixing .gitreview 2013-07-17 01:52:26 -07:00
.testr.conf Remove env vars we don't use. 2013-03-28 04:05:31 +01:00
.travis.yml Aligned tests with OpenStack standards. 2013-03-28 03:40:38 +01:00
LICENSE Aligned tests with OpenStack standards. 2013-03-28 03:40:38 +01:00
MANIFEST.in Adding MANIFEST.in and fixing .gitreview 2013-07-17 01:52:26 -07:00
README.md Rename to os-apply-config. 2013-06-14 15:30:14 +12:00
requirements.txt Make main() return rather than call sys.exit 2013-04-10 15:56:34 -07:00
setup.cfg Rename to os-apply-config. 2013-06-14 15:30:14 +12:00
setup.py Migrate to pbr and testr. 2013-03-28 02:37:45 +01:00
test-requirements.txt Align to OpenStack Hacking rules. 2013-03-28 04:03:46 +01:00
tox.ini Migrate to pbr and testr. 2013-03-28 02:37:45 +01:00

README.md

os-apply-config

Apply configuration from cloud metadata (JSON).

What does it do?

It turns a cloud-metadata file like this:

{"keystone": {"database": {"host": "127.0.0.1", "user": "keystone", "password": "foobar"}}}

into service config files like this:

[sql]
connection = mysql://keystone:foobar@127.0.0.1/keystone
...other settings...

Usage

Just pass it the path to a directory tree of templates:

sudo os-apply-config -t /home/me/my_templates

Templates

The template directory structure should mimic a root filesystem, and contain templates for only those files you want configured.

e.g.

~/my_templates$ tree
.
└── etc
    ├── keystone
    │   └── keystone.conf
    └── mysql
        └── mysql.conf

An example tree can be found here.

If a template is executable it will be treated as an executable template. Otherwise, it will be treated as a mustache template.

Mustache Templates

If you don't need any logic, just some string substitution, use a mustache template.

Metadata settings are accessed with dot ('.') notation:

[sql]
connection = mysql://{{keystone.database.user}}:{{keystone.database.password}@{{keystone.database.host}}/keystone

Executable Templates

Configuration requiring logic is expressed in executable templates.

An executable template is a script which accepts configuration as a JSON string on standard in, and writes a config file to standard out.

The script should exit non-zero if it encounters a problem, so that os-apply-config knows what's up.

The output of the script will be written to the path corresponding to the executable template's path in the template tree.

#!/usr/bin/env ruby
require 'json'
params = JSON.parse STDIN.read
puts "connection = mysql://#{c['keystone']['database']['user']}:#{c['keystone']['database']['password']}@#{c['keystone']['database']['host']}/keystone"

You could even embed mustache in a heredoc, and use that:

#!/usr/bin/env ruby
require 'json'
require 'mustache'
params = JSON.parse STDIN.read

template = <<-eos
[sql]
connection = mysql://{{keystone.database.user}}:{{keystone.database.password}}@{{keystone.database.host}}/keystone

[log]
...
eos

# tweak params here...

puts Mustache.render(template, params)

Quick Start

# install it
sudo pip install -U git+git://github.com/stackforge/os-config-applier.git

# grab example templates
git clone git://github.com/stackforge/triple-image-elements /tmp/config

# run it
os-apply-config -t /tmp/config/elements/nova/os-config-applier/ -m /tmp/config/elements/boot-stack/config.json -o /tmp/config_output