xenol's blog

Chance favors the prepared mind

Feb 12, 2017 - 2 minute read - Comments - sysadmin OpenIndiana illumos ansible

Ansible modules and OpenIndiana

Preface

Ansible is a great software for automating and managing systems. In this blog post I will post some examples how to use Ansible modules for accomplishing various tasks on OpenIndiana.

Package and package repository management

Install IPS packages

- name: Install common packages
  pkg5: name:
          - tcpdump
          - tmux
          - shells/zsh
        state=present

Remove IPS packages

- name: Remove tcpdump
  pkg5: name=tcpdump
        state=absent

Remove IPS publisher

- name: Remove openindiana.org IPS publisher
  pkg5_publisher: name=openindiana.org
                  state=absent

Configure new IPS publisher

- name: Enable hipster-encumbered IPS publisher
  pkg5_publisher: name=hipster-encumbered
                  origin=https://pkg.openindiana.org/hipster-encumbered
                  sticky=True

- name: Add local IPS repository
  pkg5_publisher: name=userland
                  origin=file:///ws/oi-userland/i386/repo
                  sticky=True

Update IPS publisher configuration

- name: Switch from http to https for openindiana.org IPS publisher
  pkg5_publisher: name=openindiana.org
                  origin=https://pkg.openindiana.org/hipster
                  sticky=True

Networking

Configure static IP address on VNIC

- name: Create VNIC on physical network interface
  dladm_vnic: name=vnic0
              link=bge0
              state=present

- name: Create IP interface on top of VNIC
  ipadm_if: name=vnic0
            state=present

- name: Configure IP address on VNIC
  ipadm_addr: addrobj=vnic0/v4
              address=172.17.0.1/24
              state=present

Enable jumbo frames on physical interface

- name: Enable jumbo frames on NIC
  dladm_linkprop: name=e1000g1
                  property=mtu
                  value=9000

Reset MTU to the default value

- name: Reset MTU on e1000g1
  dladm_linkprop: name=e1000g1
                  property=mtu
                  state=reset

Configure DHCP on VNIC

Zones

Ansible provides solaris_zone module for zone management, but not all features are supported as this module expects Solaris. However, this module is fully usable on OpenIndiana and other illumos distributions.

Create a zone on OpenIndiana and do basic configuration

- name: Install nlipkg brand package
  pkg5: name=system/zones/brand/nlipkg
        state=present

- name: Create zone 'www'
  solaris_zone: name='www'
                path=/zones/www
                config='set brand=nlipkg, set ip-type=exclusive; set autoboot=true; add net; set physical=zone0; end'
                state=installed

- name: Create sysding configuration file
  lineinfile: line='{{ item }}'
              dest=/zones/www/root/etc/sysding.conf
              mode=0400
              owner=root
              group=root
  with_items:
    - 'setup_timezone UTC'
    - 'setup_locale C'
    - 'setup_user_password root "$5$CLl7tjdz$aAan/ZZKy74Lytf4/RQ.hdsrCVYAJKlgVSlDQWosC5B"'
    - 'setup_interface "zone0" "v4" "172.17.0.11/24"'
    - 'setup_route "default" "172.17.0.1"'

- name: Start template build zone
  solaris_zone: name=www
                state=running

Boot a zone

- name: Boot zone 'www'
  solaris_zone:
    name: zone1
    state: running

Halt a zone

- name: Halt zone 'www'
  solaris_zone: name='www'
                state=stopped

Delete a zone

- name: Delete zone 'www'
  solaris_zone: name='www'
                state=absent

Detach zone

- name: Detach zone 'www'
  solaris_zone: name='www'
                state=detached