Last month i released my first puppet module at puppet forge (https://forge.puppetlabs.com/andulla/vsphere_conf) to get practice with puppet module development:
This module automates the described steps necessary to get the Puppet Labs Inc. VMware vSphere module up and running: https://forge.puppetlabs.com/puppetlabs/vsphere
It does the following:
- It installs the necessary package dependencies:
- zlib1g-dev, libxslt1-dev and build-essential for Debian 7 and 8, Ubuntu 14.04 LTS and similar via the apt-get package manager:
apt-get install zlib1g-dev libxslt1-dev build-essential
- zlib-devel, libxslt-devel, patch and gcc on RHEL 6 and 7, CentOS and similar via yum package manager:
yum install zlib-devel libxslt-devel patch gcc
- zlib1g-dev, libxslt1-dev and build-essential for Debian 7 and 8, Ubuntu 14.04 LTS and similar via the apt-get package manager:
- Install the required gems rbvmomi and hocon with command:
/opt/puppetlabs/puppet/bin/gem install rbvmomi hocon --no-ri --no-doc
- Note: the module will only work on Puppet Enterprise 2015.2 Using the gem command via /opt/puppet/bin is currently not part of this module.
- It configures the necessary credentials and optional configurations within the /etc/puppetlabs/puppet/vcenter.conf so you will get a following example vcenter.conf file:
vcenter: { host: "myvcenterhost.test.com" user: "myvcenterhostuser" password: "myvcenterhostuserpassword" port: 443 insecure: false ssl: false }
The module itself is made out of three important files:
- init.pp.: Installs the missing Packages via the puppet package resource type, the missing ruby gems via puppet package resource type using the provider puppet_gem and configures the vcenter.conf file via the file resource type and using a template file vcenter.conf.erb:
class vsphere_conf ( $packages = $vsphere_conf::params::packages, $gems = $vsphere_conf::params::gems, $provider = $vsphere_conf::params:provider, $host = $vsphere_conf::params::host, $user = $vsphere_conf::params::user, $password = $vsphere_conf::params::password, $port = $vsphere_conf::params::port, $insecure = $vsphere_conf::params::insecure, $ssl = $vsphere_conf::params::ssl, ) inherits vsphere_conf::params { #Install required packages package { $packages: ensure => installed, provider => $provider, notify => Exec['rbvmomiandhocon'], } # Install required gems package { $gems: ensure => present, provider => puppet_gem, } file { '/etc/puppetlabs/puppet/vcenter.conf': owner => 'root', group => 'root', mode => '0644', content => template('vsphere_conf/vcenter.conf.erb'), } }
- params.pp: fills the default parameter for the module itself. The package list will be created with check of the current fact osfamily (Redhat or Debian).
class vsphere_conf::params { $host = 'myvcenter.test.com' $user = 'myuser' $password = 'mypassword' $port = 443 $insecure = false $ssl = true $gems = [rbvmomi,hocon] case $::osfamily { 'Debian' : { $packages = ['zlib1g-dev','libxslt1-dev','build-essential'] $provider = 'apt' } 'Redhat' : { $packages = ['zlib-devel', 'libxslt-devel', 'patch', 'gcc'] $provider = 'yum' } } }
- vcenter.conf.erb: will be used and filled with parameters $host, $user, $password, $port, $insecure and $ssl:
vcenter: { host: "<%= @host %>" user: "<%= @user %>" password: "<%= @password %>" port: "<%= @port %>" insecure: "<%= @insecure %>" ssl: "<%= @ssl %>" }
Thats it! 3 files and you automate all the described steps. Now everyone using the Puppet Labs Inc. vSphere module can reuse to quickly setup the vSphere module inside a Puppet Enterprise environment.
Inside my Puppet Enterprise with Node Classifier it looks like this:
I can recommend the following Beginner’s Guide if you would like to start developing you own module: http://docs.puppetlabs.com/guides/module_guides/bgtm.html?_ga=1.211367442.641876350.1434375001
Time to automate!