Ask Your Question
1

puppetdb stores hash fact as string for some nodes

asked 2015-04-08 22:49:49 -0500

zsl gravatar image

updated 2015-04-09 23:10:00 -0500

Some facts supposed to be hash are stored as string in puppetdb.

For example:

curl -X GET http://localhost:8080/v3/nodes/tcentos/facts/partitions
[ {
  "value" : "sda1uuid1b97126a-beb2-4843-8c7b-4e6e12cbfbb7mount/bootsize1024000filesystemext4sda2size40916992filesystemLVM2_member",
  "name" : "partitions",
  "certname" : "tcentos"
} ]

while it should be like this:(actually this is not quite normal because of the strange escape character).

curl -X GET http://localhost:8080/v3/nodes/tfedora20/facts/partitions
[ {
  "value" : "{\"sda1\"=>{\"uuid\"=>\"8e6cda9b-54b7-4daa-a25c-1864a163f7a8\", \"size\"=>\"1024000\", \"mount\"=>\"/boot\", \"filesystem\"=>\"ext4\"}, \"sda2\"=>{\"size\"=>\"15751168\", \"filesystem\"=>\"LVM2_member\"}}",
  "name" : "partitions",
  "certname" : "tfedora20"
} ]

When I run facter partitions on tcentos node, the return value is OK.

[root@tcentos ~]# facter partitions
{"sda1"=>{"mount"=>"/boot", "filesystem"=>"ext4", "size"=>"1024000", "uuid"=>"1b97126a-beb2-4843-8c7b-4e6e12cbfbb7"}, "sda2"=>{"filesystem"=>"LVM2_member", "size"=>"40916992"}}

my Puppet Environment:

Puppet Master : 3.7.5
Puppet Agent  : 3.7.5
PuppetDB      : 2.3.0

The puppet agents and facter on all my nodes are exactly the same version. Does anybody have the same issue? Any thought is welcome!

edit retag flag offensive close merge delete

Comments

are ruby versions the same?

dsanabria gravatar imagedsanabria ( 2015-04-09 06:10:53 -0500 )edit

@dsanabria yes, 1.9.3.

zsl gravatar imagezsl ( 2015-04-09 10:57:45 -0500 )edit

Your problem is mine, too.

Kai Burghardt gravatar imageKai Burghardt ( 2015-04-09 19:31:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-04-10 02:34:02 -0500

zsl gravatar image

updated 2015-04-10 03:05:16 -0500

OK. I think I got the reason. This is about stringify_facts configuration.

we can set stringify_facts=false in puppet.conf (both agent and master) to disable flattening fact values to strings. According to the official documentation, structured facts support is enabled by default from 3.7 and later. But I guess the default behaviour is different on Open Source Puppet, so we have to explicitly add this setting.

curl -X GET http://localhost:8080/v3/nodes/tcentos/facts/partitions
[ {
  "value" : "{\"sda1\":{\"filesystem\":\"ext4\",\"mount\":\"/boot\",\"size\":\"1024000\",\"uuid\":\"1b97126a-beb2-4843-8c7b-4e6e12cbfbb7\"},\"sda2\":{\"filesystem\":\"LVM2_member\",\"size\":\"40916992\"}}",
  "name" : "partitions",
  "certname" : "tcentos"
} ]

Although the response is not a genuine JSON data. But I think I can figure out a to parse it.

Update:

If I use PuppetDB APIv4, the response is actual JSON Data... So I guess APIv3 doesn't parse the structure data?

curl -s -X GET http://puppetdb:8080/v4/nodes/tcentos/facts/partitions
[ {
  "value" : {
    "sda1" : {
      "filesystem" : "ext4",
      "mount" : "/boot",
      "size" : "1024000",
      "uuid" : "1b97126a-beb2-4843-8c7b-4e6e12cbfbb7"
    },
    "sda2" : {
      "filesystem" : "LVM2_member",
      "size" : "40916992"
    }
  },
  "name" : "partitions",
  "environment" : "production",
  "certname" : "tcentos"
} ]
edit flag offensive delete link more

Comments

2

The API docs don't do a good job of point this out, but the v3 API always returns single string values. The v4 api returns strings, integers, arrays, hashes, etc. Some detail in the 2.2.0 release notes: http://docs.puppetlabs.com/puppetdb/2.2/release_notes.html#changes-to-endpoints

csharpsteen gravatar imagecsharpsteen ( 2015-04-10 08:21:27 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-04-08 22:49:13 -0500

Seen: 338 times

Last updated: Apr 10 '15