Ask Your Question
0

pretty print site manifest?

asked 2016-11-22 07:25:04 -0500

erichymowitz gravatar image

updated 2016-11-23 07:12:15 -0500

Is there a script (ideally perl) that will look through and pretty-print my site manifest?

Something that will go through my various profiles and nodes, propogate default values, and print a list of values at the end?

I'm currently running puppet master compile HOSTNAME repeatedly, but as I get more hosts, my script takes longer and longer to complete. I don't really need a full puppet compile, I just want to see how the values end up.

I could probably write one in perl, but I know that other people could write a better one.

EDIT

Apparently I wasn't clear with what I'm looking for. I think "pretty print" was the wrong term to use. I apologize.

Given this sample setup, where I have a class with variables with default values, a class that is built upon that class with different default values, and two nodes (we use the term "string" to refer to machines being a test machine, a production machine, etc)

class profiles::generic
(
  $patchstring,
  $patchhour = 12,
  $patchminute = 0,
)
{
  class { 'systempatch' :
    string => $patchstring,
    hour => $patchhour,
    minute => $patchminute,
  }
}

class profiles::teststring
(
  $patchstring = 'test',
  $patchhour = 13,
  $patchminute = 0,
)
{
  class { 'profiles::generic' :
    patchstring => $patchstring,
    patchhour => $patchhour,
    patchminute => $patchminute,
}

node 'cutlass'
{
  class { 'profiles::generic' :
    patchstring => 'prod',
    patchminute => 30,
  }
}

node 'volvo'
  class { 'profiles::teststring' :
    patchminute => 20,
  }
}

I would like an output that tells me

  • cutlass
    • systempatch
      • string = "prod"
      • hour = 12
      • minute = 30
  • volvo
    • systempatch
      • string = "test"
      • hour = 13
      • minute = 20

As I said, I could probably write one, but if one exists, it will probably be a better one than mine.

edit retag flag offensive close merge delete

Comments

puppet lint http://puppet-lint.com/ is not about pretty printing but style checking https://docs.puppet.com/guides/style_guide.html (pretty printing is not about compiling)

Kai Burghardt gravatar imageKai Burghardt ( 2016-11-22 09:01:45 -0500 )edit

I think he means the pson file being minified instead of indented and beeline seperated. That part is easy, either install jq and pipe it through there, or through python -m json.tool

DarylW gravatar imageDarylW ( 2016-11-23 06:24:26 -0500 )edit

Given your latest edit, pretty printing is not what you're asking for. Pretty printing is about style adjustments, making your code actually printable (on paper) w/o looking gross. What you describe, is accessing the parser tree. see pp parser class http://rubydoc.info/gems/puppet/Puppet/Parser/AST

Kai Burghardt gravatar imageKai Burghardt ( 2016-11-23 15:01:16 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2016-11-23 06:21:25 -0500

DarylW gravatar image

Each machine contains the last run report (puppet config print lastrunfile)

That isn't the catalog directly, but it contains all of the info from the catalog, in addition to if it applied correctly or not on your system.

If your report runs are stored on the puppetmaster, it contains the runs for all your nodes. If you are using puppetdb, there is probably a way to query for that same information, but I haven't used it before.

edit flag offensive delete link more

Comments

Thanks. The reports are useful, but not quite what I'm looking for. I updated my question with a specific example of what I'm looking for.

erichymowitz gravatar imageerichymowitz ( 2016-11-23 07:16:59 -0500 )edit

You are asking something halfway between the two, the resulting catalog is all the raw resources you've created, final values, you want the AST turned back into puppet code with values, like a debugger?

DarylW gravatar imageDarylW ( 2016-11-24 14:41:09 -0500 )edit

@DarylW: All I want is to know that Volvo will patch at 13:20 with the "test" string. I don't care what the output format is. I have enough perl skillz to deal with that. I want something faster than "puppet master --compile volvo" that will somehow tell me what values are eventually used.

erichymowitz gravatar imageerichymowitz ( 2016-11-28 06:50:02 -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

1 follower

Stats

Asked: 2016-11-22 07:25:04 -0500

Seen: 59 times

Last updated: Nov 23 '16