Generating roles.conf from YAML

14 views
Skip to first unread message

Philip

unread,
Aug 7, 2008, 12:41:44 PM8/7/08
to slack users
I wrote a little script to generate a slack roles.conf from a YAML
file. I mostly did this to get rid of to large amounts of repetitive
data I was having to write to the roles.conf when I wanted several
hosts to have a similar set of roles. It also supports defining
dependencies between roles which effect their ordering in roles.conf.
Finally, you can specify your domain name once and it will append that
to each host entry in your roles.conf.

It is in a slightly hacky state. I've been too lazy to modify the
object that I use to store the host/role relationships... mostly
because it works well enough as is. If people find it useful, perhaps
I'll clean the code up a bit. I've included an example YAML file for
you to mess around with, and there are some very basic test cases in
test_rolegen.py. Be afraid ;-)

http://slack-users.googlegroups.com/web/rolegen-0.1.tar.gz?gda=0_Dx_UMAAADCy2dpp6YGFFZZuArtqi5ba1ymeo6EhotEFIiFDjQ6mWG1qiJ7UbTIup-M2XPURDQ52ByVFc9QJw91LxU93YIET7EkWIlwyciGi5gq1ZC0NQ

Here are a few things you can do with it:

You can generate a roles.conf (to stdout) from the example:

./rolegen.py -i example.yaml

To write it to a file:

./rolegen.py -i example.yaml -o example.roles.conf

To get a list of roles for a host:

./rolegen.py -i example.yaml -s host1

To see all hosts that use a role:

./rolegen.py -i example.yaml -r role1

To show the depgraph (DAG) if you enjoy such things:

./rolegen.py -i example.yaml -g

Usage:

./rolegen.py -h

-P

Philip Walls

unread,
Aug 9, 2008, 3:01:14 PM8/9/08
to slack users
Uploaded a new version which supports wildcard dependencies. I'll go
into some detail here, but you'll have to forgive stream-of-
consciousness delivery. Food awaits me.

The change allows you to put something like this in your YAML:

__SNIP__

role9:
depends:
- @ALL@

__SNIP__

Since there was interest in having a scripts repository in another
thread, I'll demonstrate how this feature could be used to make one
that is guaranteed to be installed before other roles run.

In roles.yaml:

__SNIP__

roles:
scripts:
before: [ @ALL@ ]

__SNIP__

Drop some files into the script role:

roles/
scripts/files/var/lib/slack/scripts/ # in anticipation of this
some day being built in ;-)
install_package*
...

And then from any other role, something like this could be in your
preinstall:

__SNIP__

#!/bin/bash

set -e

export PATH="/var/lib/slack/scripts:${PATH}"

install_package "apache2"

__SNIP__

Here's the new package: http://groups.google.com/group/slack-users/web/rolegen-0.2.tar.gz

If you're curious what install_package looks like (though it isn't
really relevant):

__SNIP__

#!/bin/bash

set -e

pkg="$1"
stat="$(dpkg-query -W --showformat='${Status} ${Package}' "${pkg}" 2>/
dev/null)"

if [ "${stat}" != "install ok installed ${pkg}" &>/dev/null ]; then
DEBIAN_FRONTEND=noninteractive apt-get -qq -y --force-yes install "$
{pkg}"
fi

__SNIP__

-P

On Aug 7, 9:41 am, Philip <slla...@gmail.com> wrote:
> I wrote a little script to generate a slack roles.conf from a YAML
> file. I mostly did this to get rid of to large amounts of repetitive
> data I was having to write to the roles.conf when I wanted several
> hosts to have a similar set of roles. It also supports defining
> dependencies between roles which effect their ordering in roles.conf.
> Finally, you can specify your domain name once and it will append that
> to each host entry in your roles.conf.
>
> It is in a slightly hacky state. I've been too lazy to modify the
> object that I use to store the host/role relationships... mostly
> because it works well enough as is. If people find it useful, perhaps
> I'll clean the code up a bit. I've included an example YAML file for
> you to mess around with, and there are some very basic test cases in
> test_rolegen.py. Be afraid ;-)
>
> http://slack-users.googlegroups.com/web/rolegen-0.1.tar.gz?gda=0_Dx_U...
Reply all
Reply to author
Forward
0 new messages