Jump to content

User:Razzi/Experiment: use puppet notice to show variable

From Wikitech

With puppet code like:

hack $ cat manifests/scope_example.pp
# scope-example.pp
# Run with puppet apply --certname www1.example.com scope-example.pp
$myvar = "Top scope value"
node 'localhost' {
  $myvar = "Node scope value"
  notice( "from www1: $myvar" )
  include myclass
}
node 'db1.example.com' {
  notice( "from db1: $myvar" )
  include myclass
}
class myclass {
  $myvar = "Local scope value"
  notice( "from myclass: $myvar" )
}

You can do

hack $ puppet apply manifests/scope_example.pp --certname localhost
Notice: Scope(Node[localhost]): from www1: Node scope value
Notice: Scope(Class[Myclass]): from myclass: Local scope value
Notice: Compiled catalog for localhost in environment production in 0.01 seconds
Notice: Applied catalog in 0.00 seconds

You can even use puppet apply -e on a server:

razzi@datahubsearch1001:~$ sudo puppet apply -e 'notice($::fqdn)'
Notice: Scope(Class[main]): datahubsearch1001.eqiad.wmnet
Notice: Compiled catalog for datahubsearch1001.eqiad.wmnet in environment production in 0.02 seconds
Notice: Applied catalog in 0.30 seconds