On 1/25/17 6:43 AM, Sans wrote:
> Dear all,
> I'm having this issue and running out of ideas.
> I have this two external facts (defined in
> /etc/facter/facts.d/extn_git_facts.txt):
> 
> |
> 
> root@p19-d-pmaster-001:~# facter|grep ks_git
> ks_git_puppet-hiera =>master                        
> ks_git_puppet-master =>develop
> |
> 
> I want to use these two facts in a template. Here is my pseudo code:
> |
> 
> <%-
>     git_repos =['puppet-hiera','puppet-master']
>     git_repos.each do|g_repo|
>         git_branch ="ks_git_#{g_repo}"
>         git_br_name =Facter.value("ks_git_#{g_repo}")
> -%>
> GIT_BRANCH      :: <%=git_branch %>
> GIT_BRANCH_NAME :: <%=git_br_name %>
> <%-
>     end
> -%>
> |
> 
> and I don't get anything returned by `git_br_name` at all. If I use the
> same code in irb console, it works just fine:
> 
> |
>  irb(main):012:0>require'facter'
>  =>true
>  irb(main):013:0>git_repos =['puppet-hiera','puppet-master']
>  =>["puppet-hiera","puppet-master"]
>  irb(main):014:0>git_repos.each do|g_repo|
>  irb(main):015:1*p Facter.value("ks_git_#{g_repo}")
>  irb(main):016:1>end
>  "master"
>  "develop"
>  =>["puppet-hiera","puppet-master"]
> |
> 
> 
> What am I doing wrong in the template? if I use some other built-in
> facts instead, e.g. `Facter.value(:hostname)` - it works just okay. Does
> mean the external facts cannot be used in template? Thanks in advance.
> 
> Best,
> Santanu
> 
> -- 

Hi Sans,

I think your ERB syntax may be off. Here's an example doing something
similar. Instead of Facter.value() just put an @ in front of the fact name.

<% @nameservers.each do |nameserver| -%>
nameserver <%= nameserver %>
<% end -%>

Best regards,
-g

-- 
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/b82abd3d-f322-f243-50be-3ca98b593afa%40garretthoneycutt.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to