On Friday, December 13, 2013 5:30:19 AM UTC-8, David Portabella wrote:

Given this puppet manifest (test.pp):
> $dir = '/tmp'
> file {'myfile':
>   path => "$dir/myfile.txt",
>   content => 'hello'
> }
>
> puppet produces this report:
> [...]
>     File[myfile]: !ruby/object:Puppet::Resource::Status
>       resource: File[myfile]
>       file: /Users/david/test.pp
>       line: 4
>       evaluation_time: 0.001354
>       change_count: 1
>       out_of_sync_count: 1
>       tags: 
>         - file
>         - myfile
>         - class
>       time: 2013-12-13 11:44:59.092716 +01:00
>       events: 
>         - !ruby/object:Puppet::Transaction::Event
>           audited: false
>           property: ensure
>           previous_value: !ruby/sym absent
>           desired_value: !ruby/sym file
>           historical_value: 
>           message: "defined content as 
> '{md5}5d41402abc4b2a76b9719d911017c592'"
>           name: !ruby/sym file_created
>           status: success
>           time: 2013-12-13 11:44:59.093067 +01:00
>       out_of_sync: true
>       changed: true
>       resource_type: File
>       title: myfile
>       skipped: false
>       failed: false
>       containment_path: 
>         - Stage[main]
>         - ""
>         - File[myfile]
> [...]
>
> so, the report tells that it has created File[myfile],
> but it does not contain the path of the file /tmp/myfile.txt.
>
> that's a pity, because it means that I cannot get a list of all the files 
> updated by puppet.
>
> is there a way to get the final path of all File resources created by 
> puppet?
> (not "$dir/myfile.txt", but "/tmp/myfile.txt")
>
 The report is focused on describing the changes that occurred during that 
run. To that end, only the title is included as that information is 
sufficient to uniquely identify the reporting resource when combined with 
resource_type. Information concerning properties that were not changed 
during the run is omitted as this data can be obtained from the catalog 
that the agent was processing.

In this specific situation, you can modify your file resource such that the 
path is used as the title:

$dir = '/tmp'
file { "$dir/myfile.txt":
  content => 'hello'
}

However, the general problem of matching changes to resources can be solved 
by loading the report and then loading the catalog and joining the two 
datasets using the resource_type and title. However, this particular task 
is one of the problems PuppetDB was designed to solve. PuppetDB stores both 
the catalogs and reports and provides an API that can be used to query the 
data.

For example, the changes related to myfile can be retrieved by querying the 
events 
endpoint <https://docs.puppetlabs.com/puppetdb/1.5/api/query/v3/events.html>of 
the PuppetDB API:

curl -G 'http://localhost:8080/v3/events' --data-urlencode query=\'["and", 
["=", "resource-type", "File"],
  ["=", "containing-class", "Testfile"],
  ["=", "certname", "pe-310-agent.puppetdebug.vlan"]]'

Which gives results similar to the following:

[ {

  "status" : "success",
  "timestamp" : "2013-12-13T17:11:39.144Z",
  "certname" : "pe-310-agent.puppetdebug.vlan",
  "containing-class" : "Testfile",
  "containment-path" : [ "Stage[main]", "Testfile", "File[myfile]" ],
  "report" : "6bed5163b50b5857921b5ec27d9147b428c684f8",
  "run-start-time" : "2013-12-13T17:11:29.382Z",
  "resource-title" : "myfile",
  "configuration-version" : "1386954691",
  "run-end-time" : "2013-12-13T17:11:36.527Z",
  "property" : "ensure",
  "message" : "defined content as '{md5}5d41402abc4b2a76b9719d911017c592'",
  "new-value" : "file",
  "old-value" : "absent",
  "line" : 44,
  "file" : "/etc/puppetlabs/puppet/modules/testfile/manifests/init.pp",
  "report-receive-time" : "2013-12-13T17:11:41.334Z",
  "resource-type" : "File"} ]

The resource contained in the catalog delivered to that node, which 
contains properties such as the path, can be retrieved by passing the 
resource Type and title to the resources 
endpoint<https://docs.puppetlabs.com/puppetdb/1.5/api/query/v3/resources.html>
:

curl -G 'http://localhost:8080/v3/resources/File/myfile' --data-urlencode 
'query=["=", "certname", "pe-310-agent.puppetdebug.vlan"]'

This returns all the parameters of interest:

[ {
  "parameters" : {
    "path" : "/tmp/myfile.txt",
    "mode" : "0755",
    "content" : "hello",
    "backup" : "main",
    "alias" : [ "/tmp/myfile.txt" ]
  },
  "line" : 45,
  "file" : "/etc/puppetlabs/puppet/modules/testfile/manifests/init.pp",
  "exported" : false,
  "tags" : [ "default", "node", "myfile", "testfile", "class", "file" ],
  "title" : "myfile",
  "type" : "File",
  "resource" : "93f90701c8f54a485246a9e3725040f1992fd90b",
  "certname" : "pe-310-agent.puppetdebug.vlan"} ]

The power of PuppetDB in this situation is that your reporting script can 
now focus on analyzing the data instead of finding and then filtering it.

Hope this helps!
-- 
Charlie Sharpsteen
Open Source Support Engineer
Puppet Labs

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/a4dba39f-5d95-437f-b252-57a44d1e4f03%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to