Issue with lookup / hiera in yaml

31 views
Skip to first unread message

Helmut Schneider

unread,
Aug 15, 2018, 10:47:10 AM8/15/18
to puppet...@googlegroups.com
Hi,

common.yaml:
variable:
baculaWorkingDirectory: '/var/lib/bacula'

variables:
baculaWorkingDirectory: '/var/lib/bacula'

config.pp:
[...]
$variables = lookup({
"name" => "variables",
"merge" => {
"strategy" => "deep",
"knockout_prefix" => "--",
# "sort_merged_arrays" => true,
},
"default_value" => [],
})
[...]

bacula.pp:
class bacula inherits config {
$test1 = lookup('variable.baculaWorkingDirectory')
#$test2 = lookup('variables.baculaWorkingDirectory')
$baculaWorkingDirectory = $variables['baculaWorkingDirectory']
notify {"Test": message => $test1}
#notify {"Test": message => $test2}
notify {"baculaWorkingDirectory": message => $baculaWorkingDirectory}
}

Notice: /var/lib/bacula
Notice: /Stage[main]/Bacula/Notify[Test]/message: defined 'message' as
'/var/lib/bacula'
Debug: /Stage[main]/Bacula/Notify[Test]: The container Class[Bacula]
will propagate my refresh event
Notice: /var/db/bacula
Notice: /Stage[main]/Bacula/Notify[baculaWorkingDirectory]/message:
defined 'message' as '/var/db/bacula'

If I uncomment #test2:

Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Function lookup() did not find a value for the
name 'variables.baculaWorkingDirectory' on node
bsdhelmut1164.charlieroot.de

What am I missing?

Thank you.

Helmut Schneider

unread,
Aug 16, 2018, 8:49:35 AM8/16/18
to puppet...@googlegroups.com
I don't get it:

$test3 = lookup('variables')
notify {"Test3": message => $test3}

Notice: /Stage[main]/Bacula/Notify[variables]/message: defined
'message' as '{"debug"=>0, "baculaConfPath"=>"/etc/bacula",
"baculaClientService"=>"bacula-fd",
"baculaDirectorService"=>"bacula-dir",
"baculaStorageService"=>"bacula-sd",
"baculaClientPackage"=>"bacula-client",
"baculaServerPackage"=>"bacula-server",
"baculaWorkingDirectory"=>"/var/lib/bacula", "baculaGID"=>"bacula",
"baculaUID"=>"bacula", "apachePackage"=>"apache2",
"apacheService"=>"apache2", "fail2banConfPath"=>"/etc/fail2ban",
"fail2banPackage"=>"fail2ban", "fail2banService"=>"fail2ban",
"logrotatePackage"=>"logrotate", "openvpnPackage"=>"openvpn",
"openvpnService"=>"openvpn", "openvpnConfPath"=>"/etc/openvpn",
"perlDbiPackage"=>"libdbi-perl",
"perlDbdMysqlPackage"=>"libdbd-mysql-perl", "puppetService"=>"puppet",
"rootUID"=>"root", "rootGID"=>"root", "rsyslogPackage"=>"rsyslog",
"rsyslogService"=>"rsyslog", "snmpdConfPath"=>"/etc/snmp",
"snmpdService"=>"snmpd", "spamassassinPackage"=>"spamassassin",
"syslogUID"=>"syslog", "syslogGID"=>"adm", "ufwConfPath"=>"/etc/ufw",
"ufwPackage"=>"ufw", "ufwService"=>"ufw", "postfixPackage"=>"postfix",
"postfixService"=>"postfix", "postfixConfPath"=>"/etc/postfix",
"amavisdPackage"=>"amavisd-new", "arjPackage"=>"arj",
"p7zipPackage"=>"p7zip-full", "amavisdConfPath"=>"/etc/amavis/conf.d",
"amavisdService"=>"amavis", "appEtcConfPath"=>"/etc",
"bindConfPath"=>"/etc/bind", "bindPackage"=>"bind9",
"bindService"=>"bind9", "clamavConfPath"=>"/etc/clamav",
"clamavPackage"=>"clamav-daemon",
"clamavService"=>"clamav-daemon-chroot",
"clamavServiceOrg"=>"clamav-daemon", "cronConfPath"=>"/etc/cron.d",
"defaultsEtcConfPath"=>"/etc/default",
"freshclamService"=>"clamav-freshclam-chroot",
"freshclamServiceOrg"=>"clamav-freshclam", "initPath"=>"/etc/init.d",
"logrotateConfPath"=>"/etc/logrotate.d",
"perlSitePath"=>"/usr/local/lib/site_perl",
"postfixLdapSearchPackages"=>["libconfig-inifiles-perl",
"libmime-lite-perl", "libnet-ldap-perl"],
"rsyslogConfPath"=>"/etc/rsyslog.d", "sasl2Service"=>"saslauthd",
"snmpdPackage"=>"snmpd",
"spamassassinConfPath"=>"/etc/mail/spamassassin",
"sudoersConfPath"=>"/etc/sudoers.d"}'

$test2 = lookup('variables.debug')
notify {"Test2": message => $test2}

Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Function lookup() did not find a value for the
name 'variables.debug' on node h2786452

Henrik Lindberg

unread,
Aug 16, 2018, 9:16:00 AM8/16/18
to puppet...@googlegroups.com
If your data looks like this:

>> variables:
>> baculaWorkingDirectory: '/var/lib/bacula'

Then you do not have a variables.debug key - you can lookup variables,
or variables.baculaWorkingDirectory

Best,
- henrik
--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Helmut Schneider

unread,
Aug 16, 2018, 9:53:44 AM8/16/18
to puppet...@googlegroups.com
Henrik Lindberg wrote:

> If your data looks like this:
>
> >> variables:
> >> baculaWorkingDirectory: '/var/lib/bacula'
>
> Then you do not have a variables.debug key - you can lookup
> variables, or variables.baculaWorkingDirectory

common.yaml:

---
netconfig:
variables:
debug: 0
baculaConfPath: '/etc/bacula'
baculaClientService: 'bacula-fd'
baculaDirectorService: 'bacula-dir'
baculaStorageService: 'bacula-sd'
baculaClientPackage: 'bacula-client'
baculaServerPackage: 'bacula-server'
baculaWorkingDirectory: '/var/lib/bacula'
baculaGID: 'bacula'
baculaUID: 'bacula'
apachePackage: 'httpd'
apacheService: 'httpd'
fail2banConfPath: '/etc/fail2ban'
fail2banPackage: 'fail2ban'
fail2banService: 'fail2ban'
logrotatePackage: 'logrotate'
openvpnPackage: 'openvpn'
openvpnService: 'openvpn'
openvpnConfPath: '/etc/openvpn'
perlDbiPackage: 'libdbi-perl'
perlDbdMysqlPackage: 'libdbd-mysql-perl'
puppetService: 'puppet'
rootUID: 'root'
rootGID: 'root'
rsyslogPackage: 'rsyslog'
rsyslogService: 'rsyslog'
snmpdConfPath: '/etc/snmp'
snmpdService: 'snmpd'
spamassassinPackage: 'spamassassin'
syslogUID: 'root'
syslogGID: 'root'
ufwConfPath: '/etc/ufw'
ufwPackage: 'ufw'
ufwService: 'ufw'

I meanwhile found out that

lookup('variables.baculaWorkingDirectory', String, 'deep')

works while

lookup('variables.baculaWorkingDirectory')

does not. The problem is that in apps/bacula.yaml

WorkingDirectory: "%{lookup('variables.baculaWorkingDirectory')}"

works (but gives an emtpy string as 'variables.baculaWorkingDirectory'
is not found) while

WorkingDirectory: "%{lookup('variables.baculaWorkingDirectory', String,
'deep')}"

does not:

Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Evaluation Error: Error while evaluating a
Function Call, Lookup of key 'profiles' failed: Syntax error in string:
%{lookup('variables.baculaWorkingDirectory', String, 'deep')} at
/etc/puppetlabs/code/modules/config/manifests/init.pp:43:15 on node
h2786452

apps/bacula.yaml:

---
profiles:
backup:
bacula:
defaults:
[...]
Client:
FileDaemon:
"%{::fqdn}-fd":
FDport: 9102
#WorkingDirectory:
"%{lookup('variables.baculaWorkingDirectory')}"
WorkingDirectory:
"%{lookup('variables.baculaWorkingDirectory', String, 'deep')}"
[...]

Henrik Lindberg

unread,
Aug 16, 2018, 10:10:08 AM8/16/18
to puppet...@googlegroups.com
You cannot give arguments to lookup as an interpolation function inside
of data. Use the commented out variant. Then use lookup_options (in your
data) to configure that lookup of 'variables' should always be a 'deep'
merge.

Helmut Schneider

unread,
Aug 16, 2018, 11:26:30 AM8/16/18
to puppet...@googlegroups.com
Henrik Lindberg wrote:

> You cannot give arguments to lookup as an interpolation function
> inside of data. Use the commented out variant. Then use
> lookup_options (in your data) to configure that lookup of 'variables'
> should always be a 'deep' merge.

Great, works now, thanks a lot!

Reply all
Reply to author
Forward
0 new messages