Ask Your Question
0

how to use hash facts in puppetdb while compiling a catalog?

asked 2016-03-09 09:30:07 -0500

zapp_prefect gravatar image

I use Puppet 3.8 + PuppetDB 2.3 ,all is ok, but when I try to use a file template fstab.erb to generate file /etc/fstab,it says

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template /tmp/fstab.erb:
Filepath: /tmp/fstab.erb
Line: 5
Detail: undefined method `[]' for nil:NilClass

Below is the content of fstab.erb

#
# /etc/fstab
#
<% @partitions.each do |part, pv| -%>
<% if pv['mount'] == '/' -%>
/dev/<%= part %>                <%= pv['mount'] %>        <%= pv['filesystem'] %>    defaults,relatime,nodiratime,barrier=0        0 1
<% elsif pv['mount'] == '/boot' -%>
/dev/<%= part %>                <%= pv['mount'] %>        <%= pv['filesystem'] %>    defaults,relatime,nodiratime,barrier=0        1 2
<% elsif pv['filesystem'] == 'swap' -%>
/dev/<%= part %>                swap        <%= pv['filesystem'] %>    defaults                                      0 0
<% else -%>
/dev/<%= part %>                <%= pv['mount'] %>        <%= pv['filesystem'] %>    defaults,relatime,nodiratime,barrier=0        0 0
<% end -%>
<% end -%>

<% if @operatingsystemmajrelease == '6' -%>
tmpfs                   /dev/shm                tmpfs   defaults                                      0 0
devpts                  /dev/pts                devpts  gid=5,mode=620                                0 0
sysfs                   /sys                    sysfs   defaults                                      0 0
proc                    /proc                   proc    defaults                                      0 0
<% end -%>

Before I use PuppetDB, It's works fine. It seems that, puppet master can not get hash facts @partitions from PuppetDB, How can I to fix this?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-03-14 22:46:31 -0500

zapp_prefect gravatar image

Finally! You can import ruby modules in your .erb files, like this:

<%
# Add one or multiple ruby line between <% -%> 
require 'json'
partitions = JSON.parse(@partitions)
-%>
<%= partitions['vda1']['filesystem'] %>

why no such content in Puppet Officall Documents ? Or this is Deprecated Features ?

edit flag offensive delete link more

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-03-09 09:29:23 -0500

Seen: 466 times

Last updated: Mar 14 '16