Forge Home

powercli

Puppet module to install VMware PowerCLI and use it to manage vCenter

2,214 downloads

2,214 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.1.1 (latest)
released Jun 25th 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'encore-powercli', '0.1.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add encore-powercli
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install encore-powercli --version 0.1.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

encore/powercli — version 0.1.1 Jun 25th 2020

Puppet-PowerCLI

Table of Contents

  1. Description
  2. Setup - The basics of getting started with powercli
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Development - Guide for contributing to the module

Description

Puppet module that manages the install of VMware PowerCLI on a Windows host. Once PowerCLI is installed we can then use it to manage VMware ESX and vCenter with Puppet resources.

How it works

+---------------+    +----------------+        +---------+
| Puppet Master | -> | PowerCLI Proxy | -----> | vCenter |---------+
+---------------+    +----------------+   |    +---------+         v
                                          |                     +-----+
                                          +-------------------> | ESX |
                                                                +-----+

Setup

Requirements

  • This module requires PowerShell (Core) 6 to be installed on the PowerCLI Proxy. Windows Server 2016 is highly recommended to avoid Windows Server 2012r2 PowerShell heartaches.
  • powershell.exe must be available in the system PATH

Beginning with PowerCLI

VMware PowerCLI is a command-line scripting tool built on PowerShell to manage VMWare environments. This puppet-powercli module uses the PowerShell Provider to run PowerCLI commands within Puppet exec blocks.

The latest version of PowerCLI is installed onto the PowerCLI proxy at the beginning of every puppet agent run via the powercli class within init.pp in this module.

Usage

This basic resource example will install a license key onto an ESXi host.

You run:

powercli::esx::license {'my-vmware-host.fqdn.tld':
  key => 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
}

Resource:

  $key,
) {
  # including our vcenter connection class
  include powercli::vcenter::connection
  # $_connect = "Connect-VIServer"
  $_connect = $powercli::vcenter::connection::connect

  exec { "License host - ${name}:":
    # Install license
    command  => "${_connect}; Get-VMHost -Name '${name}' | Set-VMHost -LicenseKey ${key}",
    # Use PowerShell to run the above command
    provider => 'powershell',
    # Only run the above command if the below 'onlyif' returns '0' 
    onlyif   => template('powercli/powercli_esx_license_hosts_onlyif.ps1.erb'),
  }
}

OnlyIf template "powercli/powercli_esx_license_hosts_onlyif.ps1.erb":

# Connect to vcenter
<%= @_connect %>

# Grab the currently installed license key
$KeyCheck = Get-VMHost -Name '<%= @name %>' | Select-Object -ExpandProperty LicenseKey 

# Host was located in vcenter and license matches the key we want installed, exit 1 so puppet skips host
if($KeyCheck -eq '<%= @key %>'){
    exit 1
}
# If the keys didn't match...
else{
   # Exit 0 so puppet installs license on current host
   exit 0
}

Limitations

  • TBD

Development

In the Development section, tell other users the ground rules for contributing to your project and how they should submit their work.

Release Notes/Contributors/Etc. Optional

If you aren't using changelog, put your release notes here (though you should consider using changelog). You can also add any additional sections you feel are necessary or important to include here. Please use the ## header.