简体   繁体   中英

Puppet getvar() function not working

I am looking at https://github.com/puppetlabs/puppetlabs-stdlib#getvar

My manifests

class test::var inherits stdlib {

$datalocation = 'site::data'
$bar = getvar("${datalocation}::bar")
# Equivalent to $bar = $site::data::bar

notify{"This is getvar() testing variable, Now bar equal to ${bar}":}

}

when i run puppet on client i get blank

[root@401 ~]# puppet agent --test --noop
...
...
Notice: /Stage[main]/test::Var/Notify[This is getvar() testing variable, Now bar equal to '']/message: current_value absent, should be This is getvar() testing variable, Now bar equal to '' (noop)

Am i missing something?

When I run the above code, part of my puppet output is the following warning:

Warning: Scope(Class[Test::Var]): Could not look up qualified variable 'site::data::bar'; class site::data could not be found

What this is saying is that site::data::bar doesn't exist in the current scope. If you define it first, then your assignment and following notification will work as expected.

class site::data {
  $bar = 'foo'
}

class test::var inherits stdlib {
  require site::data

  $datalocation = 'site::data'
  $bar = getvar("${datalocation}::bar")
  # Equivalent to $bar = $site::data::bar                                                                                                                                    

  notify{"This is getvar() testing variable, Now bar equal to ${bar}":}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM