Search code examples
puppet

Log file to view last changes made by puppet agent


If you do puppet agent -t for when agent runs in background, where is the log file where we can see the changes, other than on puppet dashboard.

I viewed puppet.conf and in main section I see logdir, but no log file is created on that location.


Solution

  • From the docs:

    When running as a service, Puppet agent logs messages to syslog. Your syslog configuration dictates where these messages will be saved, but the default location is /var/log/messages on Linux, /var/log/system.log on Mac OS X, and /var/adm/messages on Solaris.

    When started with the --logdest FILE option, Puppet agent logs to the file specified by FILE.

    https://docs.puppet.com/puppet/4.8/services_agent_unix.html#running-puppet-agent-as-a-service

    As Raul mentions, the last run report is saved as a yaml file under the statedir directory.

    Depending on your OS and which version of Puppet your using, this could be in different locations.

    For example, on my server with Puppet 4 installed:

    $ tree $(puppet agent --configprint statedir)
    /opt/puppetlabs/puppet/cache/state
    ├── classes.txt
    ├── graphs
    │   ├── expanded_relationships.dot
    │   ├── relationships.dot
    │   └── resources.dot
    ├── last_run_report.yaml
    ├── last_run_summary.yaml
    ├── resources.txt
    ├── state.yaml
    └── transactionstore.yaml
    
    1 directory, 9 files
    

    A great tool for reading this last report file is report-print. If there's a particular piece of information you need out of the last report, you could probably adapt some of the report-print code to make your own report printer.

    You can also use what's known as report processor, which is when you write custom code to control the format and process the, such as posting to a Splunk server, Slack, Hipchat etc. A simple example would be store_json, which stores the reports as JSON instead of Yaml.