puppetdb query merging returned data

asked 2018-02-23 13:44:42 -0600

jason gravatar image

I have a puppet db query

facts[ certname,name,value ] { name = 'operatingsystemrelease' or name = 'kernelrelease' or name = 'software_version' group by certname,name,value}

this query returns a large array of hashes. with multiple items per host (see hash below). I am trying to convert this hash into a single entry per host but have not been successful, any expert puppet data manipulators that could suggest a method? I still find handling and munging data in puppet to be quite difficult.

example of desired structure:

{
    "certname": "host1",
    "kernelrelease": "4.8.0-54-generic",
    "operatingsystemrelease": "16.04"
    "software_version": {
      "apache": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      },
      "php": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      }
    }
}

Ouput: of query

[
  {
    "certname": "host1",
    "name": "kernelrelease",
    "value": "4.8.0-54-generic"
  },
  {
    "certname": "host1",
    "name": "operatingsystemrelease",
    "value": "16.04"
  },
  {
    "certname": "host1",
    "name": "software_version",
    "value": {
      "apache": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      },
      "php": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      }
    }
  },
  {
    "certname": "host2",
    "name": "kernelrelease",
    "value": "4.8.0-54-generic"
  },
  {
    "certname": "host2",
    "name": "operatingsystemrelease",
    "value": "16.04"
  },
  {
    "certname": "host2",
    "name": "software_version",
    "value": {
      "apache": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      },
      "php": {
        "release": "undefined",
        "major_version": "undefined",
        "version": "undefined"
      }
    }
  },
  {
    "certname": "host3",
    "name": "kernelrelease",
    "value": "4.4.0-81-generic"
  },
  {
    "certname": "host3",
    "name": "operatingsystemrelease",
    "value": "16.04"
  },
  {
    "certname": "host3",
    "name": "software_version",
    "value": {
      "apache": {
        "release": " Apache/2.4.18 (Ubuntu)",
        "major_version": "2.4",
        "full": "Server version: Apache/2.4.18 (Ubuntu)\nServer built:   2017-06-26T11:58:04",
        "version": "2.4.18"
      },
      "php": {
        "release": "PHP 7.1.6-1~ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun  9 2017 08:26:34) ( NTS )",
        "major_version": "7.1.6",
        "full": "PHP 7.1.6-1~ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun  9 2017 08:26:34) ( NTS )\nCopyright (c) 1997-2017 The PHP Group\nZend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies\n    with Zend OPcache v7.1.6-1~ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies",
        "version": "PHP 7.1.6-1~ubuntu16.04.1+deb.sury.org+1"
      }
    }
  }
]
edit retag flag offensive close merge delete