Ask Your Question
0

Variable Package Template for Windows

asked 2014-11-11 04:27:52 -0500

DJB gravatar image

Hello all,

I am sharing a working package template for the ask community to utilize, critique and improve.

The template was created to handle packages that are installed and removed on Windows 7 workstations at the mercy of dynamic business and licensing requirements. It takes into account multiple packages, multiple physical sites, multiple source paths. It uses two custom facts. One to locate the site by the $logonserver and the other to output the list of existing software to $installed_apps

Facter.add(:logonserver) do
  setcode do
    Facter::Core::Execution.exec('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe echo $env:logonserver')
  end
end
Facter.add(:installed_apps) do
  setcode do
    Facter::Core::Execution.exec('C:\Windows\System32\cmd.exe /c wmic product get name')
  end
end

The init.pp contains a case statement sets the UNC path of the nearest software staging server

class software {
$stageserver = $logonserver ? {
    default:    => '\\centralserver\share',
    '\\pdc1'    => '\\stageserver1\share',
    '\\sdc2'    => '\\stageserver2\share',
    '\\sdc3'    => '\\stageserver3\share',
 }
}

The next part is all copy, paste, rinse, repeat for however many packages you have in your environment. All you need to do is name the class and fill in the default variable values. The $ensure variable is meant to be overridden by an ENC like foreman where Helpdesk personnel can click a button and change the desired state of a computer. The $available variable is also meant to be overridden by an ENC as packages are made available per site.

class software::name_me (
$app_name       = '',   # Official Package Name
$version_no = '',   # Official Version Number
$ensure     = '',   # Default value unless override is activated (installed or absent)
$silent     = '',   # Install switches required for silent install e.g.(/qn /norestart)
$available      = '',   # True or False value, represents if package is available in the current site.
$source     = '',   # UNC path of the installer
){
if ($ensure == 'installed') and ($available == 'true') {
    package { $app_name:
        ensure          => $version_no,
        source          => "${software::stageserver}\\${source}",
        install_options => $silent,
    }
    # Here you can add any additional resources if the package desired state is installed
}
if ($ensure == 'absent') and ($app_name in $installed_apps) {
    exec { $app_name:
        command => "cmd /c wmic product where \"name=\'${app_name}\'\" call uninstall /nointeractive",
        provider    => powershell,
    }
    # Here you can add any additional resources required post package removal
}
}
edit retag flag offensive close merge delete

Comments

The formatting was far cleaner before posting :P

DJB gravatar imageDJB ( 2014-11-11 04:31:01 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-11-11 22:22:38 -0500

llowder gravatar image

Instead of using a class that you have to copy/paste/rename, you should make that a defined resource type.

Then you can bundle your packages into a hash and use create_resources() to apply them. Bonus points - store the hash in hiera and use your hierarchy to decide which sets of packages get installed on which nodes.

edit flag offensive delete link more

Comments

Thank you very much for your suggestion llowder. I need to do some further research on this I'm sure but is the above answer on the correct path?

DJB gravatar imageDJB ( 2014-11-11 23:07:34 -0500 )edit

That looks like the approach I would take

llowder gravatar imagellowder ( 2014-11-12 06:59:53 -0500 )edit
0

answered 2014-11-11 23:06:01 -0500

DJB gravatar image

First i define the Resource Type be doing the following?

define software ($title, $version_no, $ensure, $silent, $source) {
$stageserver = $logonserver ? {
    default:    => '\\centralserver\share',
    '\\pdc1'    => '\\stageserver1\share',
    '\\sdc2'    => '\\stageserver2\share',
}   
if ($ensure == 'installed') and ($available == 'true') {
    package { $title:
        ensure          => $version_no,
        source          => "${stageserver}\\${source}",
        install_options => $silent,
    }   
}
if ($ensure == 'absent') and ($title in $installed_apps) {
        exec { $app_name:
            command => "cmd /c wmic product where \"name=\'${app_name}\'\" call uninstall /nointeractive",
            provider    => powershell,
        }
}
}

Then across different classes I call on this resource by something like this?

software { 'cool app':
ensure      => installed,
version_no  => '7.32',
source      => 'coolapp7\setup.exe',
silent      => '/qn /norestart',
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-11-11 04:27:52 -0500

Seen: 328 times

Last updated: Nov 11 '14