Apply configuration from cloud metadata.
Go to file
Marios Andreou ee9ed5cb04 Remove tripleo-multinode-container-minimal from zuul layout
The tripleo-multinode-container-minimal is being deprecated [1]
as part of wider tripleo CI optimization at [2]. Also fixes up
.gitreview otherwise this cannot get posted against victoria.
Adds some noqa for failing pep8 tests and fixes test-requirements
for issue seen at [3]. Removes the openstack-tox-lower-constraints
which failed at [4]. Instaed of fixing remove in line with all
other tripleo repos which have removed these jobs.

[1] Ie6473759383bd4b903cbe56fba9fee75a24154c4
[2] https://review.opendev.org/q/topic:tripleo-ci-reduce
[3] https://zuul.opendev.org/t/openstack/build/8e22af10ddfd4225b7c164a81b07b323
[4] https://zuul.opendev.org/t/openstack/build/4bad7e066c7b4f508ea794401bab85a2

Change-Id: I7696fbb53cfee9dad29273e17a036c5f6963f788
2021-03-01 14:58:22 +02:00
os_apply_config Remove tripleo-multinode-container-minimal from zuul layout 2021-03-01 14:58:22 +02:00
zuul.d Remove tripleo-multinode-container-minimal from zuul layout 2021-03-01 14:58:22 +02:00
.coveragerc Change ignore-errors to ignore_errors 2015-09-21 14:41:25 +00:00
.gitignore Switch to stestr 2018-07-10 18:32:59 +07:00
.gitreview Remove tripleo-multinode-container-minimal from zuul layout 2021-03-01 14:58:22 +02:00
.stestr.conf Switch to stestr 2018-07-10 18:32:59 +07: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.rst Sync Sphinx requirement 2019-06-20 10:35:21 +08:00
lower-constraints.txt Use unittest.mock instead of third party mock 2020-04-03 17:14:01 -05:00
requirements.txt Updated from global requirements 2018-03-04 10:21:00 +00:00
setup.cfg Drop python 2.7 support and testing 2019-12-27 16:03:22 +08:00
setup.py Updated from global requirements 2017-03-06 01:16:46 +00:00
test-requirements.txt Remove tripleo-multinode-container-minimal from zuul layout 2021-03-01 14:58:22 +02:00
tox.ini Drop python 2.7 support and testing 2019-12-27 16:03:22 +08:00

README.rst

Team and repository tags

image

os-apply-config

Apply configuration from cloud metadata (JSON)

What does it do?

It turns metadata from one or more JSON files 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

By default it will read config files according to the contents of the file /var/lib/os-collect-config/os_config_files.json. In order to remain backward compatible it will also fall back to /var/run/os-collect-config/os_config_files.json, but the fallback path is deprecated and will be removed in a later release. The main path can be changed with the command line switch --os-config-files, or the environment variable OS_CONFIG_FILES_PATH. The list can also be overridden with the environment variable OS_CONFIG_FILES. If overriding with OS_CONFIG_FILES, the paths are expected to be colon, ":", separated. Each json file referred to must have a mapping as their root structure. Keys in files mentioned later in the list will override keys in earlier files from this list. For example:

OS_CONFIG_FILES=/tmp/ec2.json:/tmp/cfn.json os-apply-config

This will read ec2.json and cfn.json, and if they have any overlapping keys, the value from cfn.json will be used. That will populate the tree for any templates found in the template path. See https://opendev.org/openstack/os-collect-config for a program that will automatically collect data and populate this list.

You can also override OS_CONFIG_FILES with the --metadata command line option, specifying it multiple times instead of colon separating the list.

os-apply-config will also always try to read metadata in the old legacy paths first to populate the tree. These paths can be changed with --fallback-metadata.

Templates

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

~/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+https://opendev.org/openstack/os-apply-config.git

# grab example templates
git clone https://opendev.org/openstack/tripleo-image-elements /tmp/config

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