Using Puppet to Configure Oracle Solaris Zones

The example in this section shows one way that you can declare the zone resource type in a Puppet manifest to define an Oracle Solaris Zones configuration.

Example 5-5 Configuring Oracle Solaris Zones With Puppet

The following example puppet describe command shows an excerpted list of the zone resource type characteristics:

# puppet describe zone
zone
====
Manages Oracle Solaris zones.


Parameters
----------

- **archive**
    The archive file containing an archived zone.

- **archived_zonename**
    The archived zone to configure and install

- **brand**


    The zone's brand type

- **clone**
    Instead of installing the zone, clone it from another zone.
    If the zone root resides on a zfs file system, a snapshot will be
    used to create the clone; if it resides on a ufs filesystem, a copy of
    the
    zone will be used. The zone from which you clone must not be running.

- **config_profile**
    Path to the config_profile to use to configure a solaris zone.
    This is set when providing a sysconfig profile instead of running the
    sysconfig SCI tool on first boot of the zone.


- **ensure**
    The running state of the zone.  The valid states directly reflect
    the states that `zoneadm` provides.  The states are linear,
    in that a zone must be `configured`, then `installed`, and
    only then can be `running`.  Note also that `halt` is currently
    used to stop zones.
    Valid values are `absent`, `configured`, `installed`, `running`.
.
.
.
- **zonecfg_export**
    Contains the zone configuration information. This can be passed in
    in the form of a file generated by the zonecfg command, in the form
    of a template, or a string.

- **zonepath**
    The path to zone's file system.

Providers
---------
    solaris

The zonecfg_export parameter shown in the previous output enables you to create a zone configuration file resource by running the following zonecfg -z zonename command:

# zonecfg -z testzone1
Use 'create' to begin configuring a new zone.
zonecfg:testzone> create
create: Using system default template 'SYSdefault'
zonecfg:testzone> export -f /tmp/zone.cfg
zonecfg:testzone> exit
root@puppet_server:~# cat /tmp/zone.cfg
create -b
set zonepath=/system/zones/%{zonename}
set autoboot=false
set autoshutdown=shutdown
set ip-type=exclusive
add anet
set linkname=net0
set lower-link=auto
set configure-allowed-address=true
set link-protection=mac-nospoof
set mac-address=auto
end
root@puppet_server:~# cp /tmp/zone.cfg /etc/puppetlabs/code/modules/mycompany

The zone that you create becomes configurable when the zone resource type is applied, so declare the zone resource type in the Puppet manifest as follows:

zone { 'systemazone':
  zonecfg_export => 'puppet:///modules/mycompany/zone.conf',
  ensure => 'running',
}

The ensure parameter value is installed, which is one of the valid installed or running values. In this example, the systemazone zone is created on the node.

The following command verifies that the node applied the configuration to itself successfully:

# zoneadm list -cv
  ID NAME             STATUS       PATH                       BRAND       IP
   0 global           running      /                          solaris     shared
   - systemazone      running     /system/zones/systemazone  solaris     excl

This example output shows that the systemazone non-global zone is configured, installed, and running.