| Puppet Version: 6.10.0 Puppet Server Version: 6.7.0 PuppetDB Version: 6.7.0 OS Name/Version: Ubuntu 18.04. If a ruby function returns a raw byte string, the puppet server handles it without problems, but if the returned value is used as the value of a parameter of a resource the parameter is stored base64 encoded in the puppetdb even if it only contains utf-8 conform characters. This issue only appears with puppet 6, puppet 5 is not affected. To reproduce this issue you need a puppetserver with a puppetdb. Then you need to place the ruby function were the puppetserver can find it:
require 'resolv' |
|
module Puppet::Parser::Functions |
newfunction(:rdnslookup, :type => :rvalue) do |args| |
begin |
result = Resolv.new.getname(args[0]) |
rescue Exception => e |
warning("No reverse lookup for #{args[0]}: #{e}") |
return nil |
end |
return result |
end |
end
|
and use this short code for the manifest:
$v = rdnslookup('8.8.8.8') |
notify { "type: ${type($v)}": } |
file { $v: |
path => '/tmp/test.txt', |
content => $v, |
} |
After running a node against the puppetserver you should be able to find the resource in the puppetdb postgresql database with the postgresql query described in the following section. Actual Behavior:
select * from resource_params where resource in (select resource from catalog_resources where type = 'File' and title = 'dns.google'); |
|
resource | name | value |
--------------------------------------------+---------+-------------------- |
\xefad334d873aace70a136edb5a013cf4ccfea364 | alias | ["/tmp/test.txt"] |
\xefad334d873aace70a136edb5a013cf4ccfea364 | content | "ZG5zLmdvb2dsZQ==" |
\xefad334d873aace70a136edb5a013cf4ccfea364 | path | "/tmp/test.txt" |
(3 rows |
I would expect, that the content parameter is not base64 encoded. Desired Behavior:
select * from resource_params where resource in (select resource from catalog_resources where type = 'File' and title = 'dns.google'); |
|
resource | name | value |
--------------------------------------------+---------+------------------- |
\x9f6834bb815051a24387e82bd0845a8b46164400 | alias | ["/tmp/test.txt"] |
\x9f6834bb815051a24387e82bd0845a8b46164400 | content | "dns.google" |
\x9f6834bb815051a24387e82bd0845a8b46164400 | path | "/tmp/test.txt" |
(3 rows)
|
If .encode('UTF-8') is append to the result of the ruby function the desired behavior is achieved. But because it worked with puppet 5 and the issue is very annoyingly to debug, I hope that the issue can be fixed in puppet. |