Finally found workaround for problem with German windows clients

204 views
Skip to first unread message

Andy Spiegl

unread,
Jan 29, 2014, 1:13:43 PM1/29/14
to puppet...@googlegroups.com
A while ago I asked here for solutions with windows and puppet 3.x
I always got this error during the agent run:
> Could not intern from pson: "\xE4" on US-ASCII

After trying and debugging for a long time I finally found the right
comment in the right bug report:
http://projects.puppetlabs.com/issues/12702
https://tickets.puppetlabs.com/browse/PUP-1225

The problem is/was that in a German Windows facter answers with German
umlauts in windows-1250 character set instead of UTF-8. This is
something Puppet can't handle and quits.
C:\Program Files (x86)\Puppet Labs\Puppet\bin>facter timezone
Mitteleurop\344ische Zeit

In the bug report the user comment describes an (ugly) workaround to this:
One has to patch this file (on ALL client PCs!):
C:/Program Files (x86)/Puppet Labs/Puppet/facter/lib/facter/timezone.rb
----------------------------
+ Iconv.iconv("UTF-8", "windows-1250",Time.new.zone)
- Time.new.zone
----------------------------

After doing that the puppet agent finally runs without throwing errors. \o/
Hopefully this will be fixed upstream soon. The bug is 2 years old!

HTHH someone,
Andy.


--
People with courage and character always seem sinister to the rest.
(Hermann Hesse)

Andy Spiegl

unread,
Jan 29, 2014, 1:28:02 PM1/29/14
to puppet...@googlegroups.com
Following up on my own post:

> One has to patch this file (on ALL client PCs!):
> C:/Program Files (x86)/Puppet Labs/Puppet/facter/lib/facter/timezone.rb
> ----------------------------
> + Iconv.iconv("UTF-8", "windows-1250",Time.new.zone)
> - Time.new.zone
> ----------------------------

I just found that iconv is deprecated in ruby and one is supposed to
use String#encode instead. Otherwise "puppet --agent --test" shows a
deprecation warning at every run.

Okay, did that. Now my timezone.rb looks like this:
----------------------------
Facter.add("timezone") do
setcode do
Time.new.zone.encode("UTF-8", "windows-1250")
end
end
----------------------------

Bye,
Andy.


--
If an economist can't give you his phone number, he'll give you an
estimate. (Jack Valenti)

Josh Cooper

unread,
Feb 4, 2014, 1:09:28 AM2/4/14
to puppet...@googlegroups.com
Hi Andy,


On Wed, Jan 29, 2014 at 10:28 AM, Andy Spiegl <puppe...@spiegl.de> wrote:
Following up on my own post:

> One has to patch this file (on ALL client PCs!):
>  C:/Program Files (x86)/Puppet Labs/Puppet/facter/lib/facter/timezone.rb
> ----------------------------
>   +     Iconv.iconv("UTF-8", "windows-1250",Time.new.zone)
>   -     Time.new.zone
> ----------------------------

I just found that iconv is deprecated in ruby and one is supposed to
use String#encode instead.  Otherwise "puppet --agent --test" shows a
deprecation warning at every run.

We started bundling ruby 1.9 into the Puppet 3.2 MSI, so you are safe to call String#encode provided you are using that version or newer, and it sounds like you are. For anyone else on an older version, e.g. 3.1, you'll want to use Iconv, as String#encode doesn't exist in ruby 1.8


Okay, did that.  Now my timezone.rb looks like this:
----------------------------
Facter.add("timezone") do
  setcode do
    Time.new.zone.encode("UTF-8", "windows-1250")

This assumes Time.new.zone returns a string encoded with the Windows-1250 code page. You are probably better off omitting the source encoding, since ruby should already know what it is:

       Time.new.zone.encode("UTF-8")

The only time I would recommend specifying the source encoding is if ruby gets it wrong, e.g. ruby claims the String is US-ASCII when you know for certain it's UTF-16LE[1].

  end
end
----------------------------


Also, starting in facter 2, all fact values will be UTF-8 encoded before serializing them to the puppet master. As we get closer to RC status, it would be great if you could help test facter on your systems.

Josh


--
Josh Cooper
Developer, Puppet Labs

Join us at PuppetConf 2014September 23-24 in San Francisco - http://bit.ly/pupconf14

Andy Spiegl

unread,
Feb 7, 2014, 10:04:20 AM2/7/14
to puppet...@googlegroups.com
Hi Josh,

> This assumes Time.new.zone returns a string encoded with the Windows-1250
> code page. You are probably better off omitting the source encoding, since
> ruby should already know what it is:
>
> Time.new.zone.encode("UTF-8")

Thanks for this information!

While facter 2 isn't out, could you include that patch in the MSI please?
That would save us from patching ALL the systems manually.

Thanks and have a nice weekend,
Andy.


--
Happiness is not a destination. It is a method of life. -- Burton Hills
Reply all
Reply to author
Forward
0 new messages