Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fixtures:
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib
powershell: https://github.com/puppetlabs/puppetlabs-powershell
win_facts: https://github.com/liamjbennett/puppet-win_facts
download_file: https://github.com/opentable/puppet-download_file
remote_file: https://github.com/lwf/puppet-remote_file
symlinks:
dotnet: "#{source_dir}"
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ before_install: rm Gemfile.lock || true
script: bundle exec rake test
matrix:
include:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.7.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.0"
env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 3.0" STRICT_VARIABLES=yes FUTURE_PARSER="yes"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 4.0"

deploy:
provider: puppetforge
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source "https://rubygems.org"

group :test do
gem "rake"
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0'
gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 4.0'
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
gem "puppetlabs_spec_helper"
gem "metadata-json-lint"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ Ensures the state of .net on the system. Present or Absent.
The version of .net that you want to be managed by this definition.

#####`package_dir`
If installing .NET from a directory or a mounted network location then this is that directory
If installing .NET from a directory or a mounted network location then this is
that directory. If the version of .NET being installed is a Windows feature, it
may sometimes be necessary to specify package\_dir as the path to installation
media, such as `D:\sources\sxs`.

##Reference

Expand Down
33 changes: 33 additions & 0 deletions lib/facter/dotnet4version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Facter.add(:dotnet4version) do
confine :kernel => :windows
setcode do
require 'win32/registry'
keyname = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
begin
Win32::Registry::HKEY_LOCAL_MACHINE.open(keyname) do |reg|
begin
value = reg['Release'].to_i
rescue
puts '4.0'
exit
end
case reg['Release'].to_i
when 378389
'4.5'
when 378675,378675
'4.5.1'
when 379893
'4.5.2'
when 393295
'4.6'
when 394254,394271
'4.6.1'
else
'unknown'
end
end
rescue
puts 'not installed'
end
end
end
108 changes: 77 additions & 31 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,100 @@
# }
#
define dotnet(
$ensure = 'present',
$version = '',
$package_dir = ''
) {
Enum['3.5', '4.0', '4.5', '4.5.1', '4.5.2']
$version,

Enum['present', 'absent']
$ensure = 'present',

validate_re($ensure,['^(present|absent)$'])
validate_re($version,['^(3.5|4\.0|4\.5(\.\d)?)$'])
Variant[String, Undef]
$package_dir = undef,
) {

include dotnet::params

if $::os['family'] != 'windows' {
fail("dotnet ${version} is not supported on ${::os['family']}")
}

$windows_version = $::os['release']['full']

case $version {
$::dotnet4version: {
$type = 'noaction'
}
'3.5': {
case $::operatingsystemversion {
/^Windows.Server.(2008|2012).?(R2)?.*/: { $type = 'feature' }
/^Windows (XP|Vista|7|8|8.1).*/: { $type = 'package' }
default: { $type = 'err' err("dotnet ${version} is not support on this version of windows") }
case $windows_version {
/^2012/: {
$type = 'feature'
$feature = 'NET-Framework-Features'
}
'2008 R2': { $type = 'feature' }
'7', '8', '8.1': { $type = 'dism' }
/^2003/, '2008', 'XP', 'Vista': { $type = 'package' }
default: { $type = 'err' }
}
}
'4.0': {
case $::operatingsystemversion {
/^Windows.(Server)?.?(2003|2008|2012|XP|Vista|7|8.*).?(R2)?.*/: { $type = 'package' }
default: { $type = 'err' err("dotnet ${version} is not support on this version of windows") }
case $windows_version {
/^2012/, '8', '8.1': { $type = 'builtin' }
/^2003/, /^2008/, 'XP', 'Vista', '7': { $type = 'package' }
default: { $type = 'err' }
}
}
/4\.5(\.\d)?/: {
case $::operatingsystemversion {
/^Windows.(Server)?.?(2008|2012|Vista|7|8.*).?(R2)?.*/: { $type = 'package' }
default: { $type = 'err' err("dotnet ${version} is not support on this version of windows") }
'4.5': {
case $windows_version {
/^2012/, '8', '8.1': { $type = 'builtin' }
/^2003/, /^2008/, 'XP', 'Vista', '7': { $type = 'package' }
default: { $type = 'err' }
}
}
default: {
$type = 'err'
err("dotnet does not have a version: ${version}")
'4.5.1': {
case $windows_version {
'2012 R2', '8.1': { $type = 'builtin' }
/^2003/, /^2008/, '2012', 'XP', 'Vista', '7', '8': { $type = 'package' }
default: { $type = 'err' }
}
}
'4.5.2': {
case $windows_version {
/^2003/, /^2008/, /^2012/, 'XP', 'Vista', '7', '8', '8.1': { $type = 'package' }
default: { $type = 'err' }
}
}
default: { $type = 'err' }
}

if $type == 'feature' {
dotnet::install::feature { "dotnet-feature-${version}":
ensure => $ensure,
version => $version
case $type {
'feature': {
dotnet::install::feature { "dotnet-feature-${version}":
ensure => $ensure,
version => $version,
feature => $feature,
source => $package_dir,
}
}
} elsif $type == 'package' {
dotnet::install::package { "dotnet-package-${version}":
ensure => $ensure,
version => $version,
package_dir => $package_dir
'dism': {
dotnet::install::dism { "dotnet-dism-${version}":
ensure => $ensure,
version => $version,
}
}
'package': {
dotnet::install::package { "dotnet-package-${version}":
ensure => $ensure,
version => $version,
package_dir => $package_dir,
}
}
'builtin': {
# This .NET version is built into the OS. No configuration required.
}
'noaction': {
# Desired .NET version is already present
}
default: {
fail("dotnet ${version} is not supported on windows ${windows_version}")
}
} else {

}
}
23 changes: 23 additions & 0 deletions manifests/install/dism.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
define dotnet::install::dism (
$ensure = 'present',
$version = '',
) {

if $ensure == 'present' {
exec { "install-dotnet-dism-${version}":
command => 'DISM /Online /Enable-Feature /FeatureName:NetFx3 /NoRestart',
creates => "C:/Windows/Microsoft.NET/Framework/v${version}",
provider => powershell,
logoutput => true,
}
} else {
exec { "uninstall-dotnet-dism-${version}":
command => 'DISM /Online /Disable-Feature /FeatureName:NetFx3 /NoRestart',
onlyif => "If (-Not(Test-Path C:/Windows/Microsoft.NET/Framework/v${version})) { Exit 1 }",
provider => powershell,
logoutput => true,
}
}

}
23 changes: 15 additions & 8 deletions manifests/install/feature.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#
define dotnet::install::feature(
$ensure = 'present',
$version = ''
$version,
$ensure = 'present',
$feature = 'AS-NET-Framework',
$source = undef,
) {

$source_flag = $source ? {
undef => '',
default => "-source ${source}",
}

if $ensure == 'present' {
exec { "install-feature-${version}":
command => 'Import-Module ServerManager; Add-WindowsFeature as-net-framework',
exec { "install-dotnet-feature-${version}":
command => "Import-Module ServerManager; Add-WindowsFeature ${feature} ${source_flag}",
provider => powershell,
logoutput => true,
unless => "Test-Path C:\\Windows\\Microsoft.NET\\Framework\\v${version}",
creates => "C:/Windows/Microsoft.NET/Framework/v${version}",
}
} else {
exec { "uninstall-feature-${version}":
command => 'Import-Module ServerManager; Remove-WindowsFeature as-net-framework',
exec { "uninstall-dotnet-feature-${version}":
command => "Import-Module ServerManager; Remove-WindowsFeature ${feature}",
provider => powershell,
logoutput => true,
onlyif => "Test-Path C:\\Windows\\Microsoft.NET\\Framework\\v${version}",
onlyif => "If (-Not(Test-Path C:/Windows/Microsoft.NET/Framework/v${version})) { Exit 1 }",
}
}

Expand Down
59 changes: 30 additions & 29 deletions manifests/install/package.pp
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
#
define dotnet::install::package(
$ensure = 'present',
$version = '',
$ensure = 'present',
$version = '',
$package_dir = ''
) {

include dotnet::params

$url = $dotnet::params::version[$version]['url']
$exe = $dotnet::params::version[$version]['exe']
$key = $dotnet::params::version[$version]['key']

$url = $dotnet::params::version[$version]['url']
$exe = $dotnet::params::version[$version]['exe']
$package = $dotnet::params::version[$version]['package']
$conflicts = $dotnet::params::version[$version]['conflicts']

if "x${package_dir}x" == 'xx' {
$source_dir = 'C:\Windows\Temp'
if $ensure == 'present' {
download_file { "download-dotnet-${version}" :
url => $url,
destination_directory => $source_dir
}
} else {
file { "C:/Windows/Temp/${exe}":
ensure => absent
}
$source_file = "C:/Windows/Temp/${exe}"
remote_file { $source_file:
ensure => $ensure,
source => $url,
}
} else {
$source_dir = $package_dir
$source_file = "${package_dir}/${exe}"
}

package { $package:
ensure => $ensure,
source => $source_file,
install_options => ['/q', '/norestart'],
uninstall_options => ['/x', '/q', '/norestart'],
}

if $ensure == 'present' {
exec { "install-dotnet-${version}":
command => "& ${source_dir}\\${exe} /q /norestart",
provider => powershell,
logoutput => true,
unless => "if ((Get-Item -LiteralPath \'${key}\' -ErrorAction SilentlyContinue).GetValue(\'DisplayVersion\')) { exit 0 }"
}
} else {
exec { "uninstall-dotnet-${version}":
command => "& ${source_dir}\\${exe} /x /q /norestart",
provider => powershell,
logoutput => true,
unless => "if ((Get-Item -LiteralPath \'${key}\' -ErrorAction SilentlyContinue).GetValue(\'DisplayVersion\')) { exit 1 }"
# Some versions of .NET are in-place upgrades of others. Installation of
# .NET 4.5, for example, will replace the 4.0 package. In order to disallow
# Puppet from continuously trying to install .NET 4.0 in the event dotnet
# resources for both 4.0 and 4.5 have been added to the catalog, create a
# package=absent resource for each conflicting version. This will cause the
# conflict to be caught when a catalog is compiled for the node.
$conflicts.each |$conflict| {
package { $dotnet::params::version[$conflict]['package']:
ensure => absent,
before => Package[$package],
uninstall_options => ['/x', '/q', '/norestart'],
}
}
}

Expand Down
Loading