VMWare Tools

We are running several VMWare ESXi servers, and the open-vm tools wouldn’t allow us to see some statistics on the VMs. So I came up with this module. In order to use it, you need an NFS server to export a share with the vmware tools extracted into a directory on that share. For example, on the machine autofs.domain.com we’re sharing /exports/puppet. On that share we extracted VMwareTools-4.0.0-236512.tar.gz, creating the directory vmware-tools-distrib.

Our systems all run Ubuntu linux, so you’ll have to flavor to taste on other systems. Also, the variables mountpoint, share, and server could be set outside the class depending on your needs.

class vmware::tools::install {
    $openvmtools = ["open-vm-source", "open-vm-tools"]
    $prereqs = ["build-essential","linux-headers-$kernelrelease", "psmisc"]
    $mountpoint = "/usr/local/src/puppet"
    $share = "/exports/puppet"
    $server = "autofs.domain.com"
     
    # install vmware tools prereqs
    package { $prereqs:
        ensure => present,
    }  
     
    package { $openvmtools:
        ensure => purged,
    }  
     
    # we need to mount the nfs share to get at the install script
    exec { "create mountpoint":
        command => "mkdir -p ${mountpoint}",
        unless  => "test -d ${mountpoint}",
    }  
     
    exec { "mount puppetshare":
        command  => "mount -t nfs ${server}:${share} $mountpoint",
        timeout  => 300,
        logoutput => true,
        require  => Exec["create mountpoint"],
    }  
     
    exec { "unmount puppetshare":
        command  => "umount $mountpoint",
        timeout  => 300,
        logoutput => true,
        require  => Exec["install vmwaretools"],
    }  
     
    exec { "install vmwaretools":
        creates  => "/etc/vmware-tools",
        environment => ["PAGER=/bin/cat","DISPLAY=:9"],
        cwd      => "/usr/local/src/puppet/vmware-tools-distrib",
        command  => "./vmware-install.pl -d",
        logoutput => true,
        timeout  => 300,
        require  => Exec["mount puppetshare"],
    }  
     
    service { "vmware-tools":
        ensure => running,
        enable => true,
        hasstatus => false,
        pattern => "vmware-guestd --background",
        require => [Package[$prereqs], Exec["install vmwaretools"]],
    }   
}       
         
class vmware::tools {
     include vmware::tools::install
}