Installing fonts on Windows using Puppet
I was recently tasked to install a group of fonts on windows systems. In order to do it the Internet way, you have to:
- Install the font on a system
- Export the registry file
- Create a GPO
- Place the font in an accessible location (domain readable)
- Make sure the GPO has the .reg and the font file installing
- Reboot the machine 2-3 times
Some have also suggested to install fonts via a packaged .msi – Something I also tried which did not work. Since my machines already have puppet installed, I went that route.
mkdir fonts/files/ #where the FontReg file resides
mkdir fonts/files/fonts #where the fonts reside
mkdir fonts/manifests/ #where the below init.pp file resides
Contents of init.pp are below:
class fonts {
case $operatingsystem {
windows: {
exec { 'FontReg':
command => 'C:\Windows\FontReg.exe',
path => $::path,
refreshonly => true,
require => File['C:\Windows\FontReg.exe'],
}
exec { 'FixFonts':
command => 'cmd.exe /c C:\Windows\font_ownership.bat',
path => $::path,
refreshonly => true,
require => File['C:\Windows\font_ownership.bat'],
}
file { 'C:\Windows\font_ownership.bat':
ensure => present,
notify => Exec["FixFonts"],
source_permissions => ignore,
content => "attrib -r -s c:\Windows\Fonts
takeown /f c:\Windows\Fonts /r /d n
cacls c:\Windows\Fonts /e /t /g users:c
cacls c:\Windows\System32\FNTCACHE.DAT /e /t /g users:c",
}
file { 'C:\Windows\FontReg.exe':
source => $architecture ? {
"x86" => "puppet:///modules/fonts/FontReg32.exe",
"x64" => "puppet:///modules/fonts/FontReg64.exe",
default => "unsupported architecture"
},
source_permissions => ignore,
}
$fonts = ["font-name1.otf","fontname2.ttf"];
$fonts.each |$font| {
file {"C:\\Windows\\Fonts\${font}":
source => "puppet:///modules/fonts/fonts/${font}",
ensure => present,
notify => Exec["FontReg"],
require => [File['C:\Windows\FontReg.exe'],File['C:\Windows\font_ownership.bat'],],
source_permissions => ignore
}
}
}
}
}
Required programs:
- FontReg – http://code.kliu.org/misc/fontreg/
- Puppet Future Parser (3.7.5+)
Known Limitations
- In order to actually place the files on UAC systems, you have to take ownership of the font folder. This is done in the puppet script.
- I am using an iterator because there are some fonts that are installed on your system which prevent overwriting (even after you forcibly take ownership of the folder). ADP.ttf … I am looking at you!