dalen / puppet-puppetdbquery

Query functions for PuppetDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The hash returned from resource query wrapped in brackets

bellaxie opened this issue · comments

Hi Dalen,

I might be asking a silly question. I queried a resource,
class queryrc () {
$resources = query_resources(false, 'File["/var/tmp/test_backup.txt"]', false)
notice ( $resources[title] )
}
It did return a bunch of info of the resource in a hash, but the hash was wrapped in brackets, it made any $resources[key] failed.
Here is what is returned:
[
{
tags => [class, file, node],
file => /etc/puppetlabs/code/environments/production/manifests/hosting/nginx.pp,
type => File,
title => /var/tmp/test_backup.txt,
line => 29,
resource => 7b7830adf2de0ac43311840b45122a8e93fdf3dd,
environment => production,
certname => ***,
parameters => {backup => false, ensure => file, group => root, mode => 0644, owner => root},
exported => false
}
]

Puppet does seem to have any programmatic function to remove the brackets, how did you read the values in the hash then?

Never mind, I found regsubst can replace character in string

Nope, regsubst doesn't seem to work in this case as $resources is not a string, regsubst threw error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, 'regsubst' expects one of:
(Variant[Array[String], String] target, String pattern, Variant[String, Hash[String, String]] replacement, Pattern[/^[GEIM]*$/] flags?, Enum['E', 'N', 'S', 'U'] encoding?)
rejected: parameter 'target' variant 0 index 0 expects a String value, got Struct
rejected: parameter 'target' variant 1 expects a String value, got Tuple
(Variant[Array[String], String] target, Variant[Regexp, Type[Regexp]] pattern, Variant[String, Hash[String, String]] replacement, Pattern[/^G?$/] flags?)
rejected: parameter 'target' variant 0 index 0 expects a String value, got Struct

Never mind, I misunderstood it.