I'm using LXC as a lab platform for testing SaltStack scripts. The lab consists of +5 Ubuntu 12.04 LTS containers, which I create by cloning a template container with
Once I create the template container and install
salt-minion, the template gets its Salt
minion_id based on
test-template). If I
lxc-clone this template, all clones will have that template's
minion_id, but I would like clones to have
minion_id matching their
Is there a way to make this scripted with
bash or should I take another path to the same effect?
I looked into some of
lxc scripts and found out that
lxc scripts use
/usr/share/lxc/lxc.functions file which defines
get_default_lxcpath function, so my current script looks something like this:
. /usr/share/lxc/lxc.functions # clone template lxc-clone -o $template -n "$container" # create saltstack minion config dir if does not exist minion_id_path="$(get_default_lxcpath)/$container/rootfs/etc/salt" mkdir -p "$minion_id_path" # set minion-id directly from container name echo "$container" > "$minion_id_path/minion_id"
I don't like this solution since it depends heavily on internals of both lxc and saltstack, but does the job.
After suggestion in comments about how
salt-minion will generate new
minion_id when existing one is deleted, I reduced this to two commands:
. /usr/share/lxc/lxc.functions # clone template lxc-clone -o $template -n "$container" # delete minion_id to allow salt-minion to generate a new one rm "$(get_default_lxcpath)/$container/rootfs/etc/salt/minion_id"
I'd still like to see more generic/robust approach not depending on SaltStack and LXC internals.