Ansible modules for SmartOS imgadm and vmadm

As mentioned in an earlier post I’d been working on two new Ansible modules; for imgadm(1M) and vmadm(1M). So here I want to demonstrate these new modules which will be part of Ansible 2.3. imgadm The imgadm module allow for managing both images and data sources. Let’s start by adding a new data source:

  • name: Add datasets.at source imgadm: source: ‘http://datasets.at/' state: present And we can remove it just as easily:

Running Ansible in the SmartOS global zone

None of the machines I currently run SmartOS on are big enough to run SDC/Triton, so I looked at Rundeck for creating zone definitions. and provisioning new zones as jobs. However Rundeck is unable to dynamically add new option fields. This is required for example in order to manage fields with an arbitrary number of keys, such as the network interfaces or disks. In the meantime I’ve wanted to be able to run Ansible on my SmartOS nodes for a while now.

Fun with Ansible variable interpolation

After losing some hair over the question how does Ansible do hiera-style %{} variable interpolation?I figured I’d jot down my findings. If nothing else, it’ll serve as a handy cheatsheet for future me. Background In Hiera one can do variable interpolation and internal lookups. So that’s Hiera calls withing Hiera. Very handy to reduce deplication as it helps to compose variables out of values from other layers in your hierarchy. For example on an office level you can define your gateway, and on a node-level you can re-use the value of the gateway in your per-interface config:

OpenBSD pkg.conf installpath handling with Ansible

Probably everyone using Ansible on OpenBSD figured this out already, but I thought it was quite a nifty application of Jinja templating. The way pkg.conf is built when using multiple installpath lines is: installpath = mirror1 installpath += mirror2 The template I settled on is: {# Magic for handling the '=' vs '+=' #} {% if 'installpath' in base_openbsd_pkgconf %} {% set first = True -%} {% for i in base_openbsd_pkgconf['installpath'] %} installpath {% if not first %}+{% endif %}= {{ i }} {% set first = False -%} {% endfor -%} {% endif -%} Where base_openbsd_conf[‘installpath’] is an array of mirror addresses:

Ansible pkgin module improvements

The default pkgsrc package manager for a bunch of platforms, including SmartOS, is pkgin. While working on a role for dsapid (see: Setting up a SmartOS image server) I noticed that several pieces of functionality of pkgin were not supported by the Ansible module. As a result one couldn’t use the module in a newly provisioned zone. This was due to the fact that in a fresh zone the pkgin cache is not yet populated, so installing a package would fail.