At Logilab, we've been using Salt for one year to manage our own infrastructure. I
wanted to use it to manage a specific configuration: C++ development. When I
instantiate a Virtual Machine with a Debian image, I don't want to spend time
to install and configure a system which fits my needs as a C++ developer:
This article is a very simple recipe to get a C++ development environment, ready
to use, ready to hack.
Quite simple: I use the YAML file format used by Salt to describe what I want. To
install these two editors, I just need to write:
vim-nox:
pkg.installed
emacs23-nox:
pkg.installed
For Mercurial, you'll guess:
mercurial:
pkg.installed
You can write these lines in the same init.sls file, but you can also decide
to split your configuration into different subdirectories: one place for each thing.
I decided to create a dev and editor directories at the root of my salt
config with two init.sls inside.
That's all for the editors. Next step: specific C++ development packages.
In a cpp folder, I write a file init.sls with this content:
gcc:
pkg.installed
g++:
pkg.installed
gdb:
pkg.installed
cmake:
pkg.installed
automake:
pkg.installed
libtool:
pkg.installed
pkg-config:
pkg.installed
colorgcc:
pkg.installed
The choice of these packages is arbitrary. You add or remove some as you
need. There is not a unique right solution. But I want more. I want some LLVM
packages. In a cpp/llvm.sls, I write:
llvm:
pkg.installed
clang:
pkg.installed
libclang-dev:
pkg.installed
{% if not grains['oscodename'] == 'wheezy' %}
lldb-3.3:
pkg.installed
{% endif %}
The last line specifies that you install the lldb package if your Debian
release is not the stable one, i.e. jessie/testing or sid in my case. Now, just
include this file in the init.sls one:
# ...
# at the end of 'cpp/init.sls'
include:
- .llvm
Organize your sls files according to your needs. That's all for packages
installation. You Salt configuration now looks like this:
.
|-- cpp
| |-- init.sls
| `-- llvm.sls
|-- dev
| `-- init.sls
|-- edit
| `-- init.sls
`-- top.sls
Start your VM and install a masterless Salt on it
(e.g. apt-get install salt-minion). For launching Salt locally on your
naked VM, you need to copy your configuration (through scp or a DVCS) into
/srv/salt/ directory and to write the file top.sls:
base:
'*':
- dev
- edit
- cpp
Then just launch:
> salt-call --local state.highstate
as root.
You're right. At the beginning of the post, I talked about a "ready to use"
Mercurial with some HG extensions. So I use and copy the default
/etc/mercurial/hgrc.d/hgext.rc file into the dev directory of my Salt
configuration. Then, I edit it to set some extensions such as color, rebase,
pager. As I also need Evolve, I have to clone the source code from
https://bitbucket.org/marmoute/mutable-history. With Salt, I can tell "clone
this repo and copy this file" to specific places.
So, I add some lines to dev/init.sls.
https://bitbucket.org/marmoute/mutable-history:
hg.latest:
- rev: tip
- target: /opt/local/mutable-history
- require:
- pkg: mercurial
/etc/mercurial/hgrc.d/hgext.rc:
file.managed:
- source: salt://dev/hgext.rc
- user: root
- group: root
- mode: 644
The require keyword means "install (if necessary) this target before cloning". The other
lines are quite self-explanatory.
In the end, you have just six files with a few lines. Your configuration now
looks like:
.
|-- cpp
| |-- init.sls
| `-- llvm.sls
|-- dev
| |-- hgext.rc
| `-- init.sls
|-- edit
| `-- init.sls
`-- top.sls
You can customize it and share it with your teammates. A step further would be
to add some configuration files for your favorite editor. You can also imagine
to install extra packages that your library depends on. Quite simply add a
subdirectory amazing_lib and write your own init.sls. I know I often
need Boost libraries for example. When your Salt configuration has
changed, just type: salt-call --local state.highstate.
As you can see, setting up your environment on a fresh system will take you only a
couple commands at the shell before you are ready to compile your C++ library,
debug it, fix it and commit your modifications to your repository.