Ask Your Question
0

Unable to get data from hiera. It must be simple....

asked 2016-01-06 00:31:49 -0600

Aleksandr Kushch gravatar image

My end goal is to iterate through a puppet hash and configure multiple VRFs. I was able to do that when the hash is locally defined using below code:

   $tenant_vrf_info = 
   {
      1=>{vrf=>"evpn-tenant-1", l3_vni=>"5010", rd=>"2000:5010", import=>"2000:5010"},
      2=>{vrf=>"evpn-tenant-2", l3_vni=>"5020", rd=>"2000:5020", import=>"2000:5020",
   }

   $tenant_vrf_info.each |$tenant,$value|
   {
      $tenant_id  = "$tenant"
      $tenant_vrf_context = "${value[vrf]}"
      $tenant_l3_vni = "${value[l3_vni]}"



        cisco_command_config 
        {
          $tenant_id:
          command => "
            vrf context $tenant_vrf_context
             vni ${value[l3_vni]}
            address-family ipv4 unicast
           " 
         }
        }

I decided to get this data from Hiera. This is when the nightmare began... I cannot get the data out of the hash. I just want the data out hiera so I can iterate through it using .each.

Below is my setup. When I run below code I get this error:

Evaluation Error: Empty string title at 0. Title strings must have a length greater than zero.

YAML File:

---
vrfs:      
 vrf-evpn-tenant-2:   
   l3_vni: 20101
   rd: '2000:20101'     
 vrf-evpn-tenant-3:
   l3_vni: 20102 
   rd: '2000:20102'

HIERA:

hiera -d vrfs
{"vrf-evpn-tenant-2"=>{"l3_vni"=>20101, "rd"=>"2000:20101"},
 "vrf-evpn-tenant-3"=>{"l3_vni"=>20101, "rd"=>"2000:20101"}}

Puppet Manifest:

class rbc_vrf
{
       include install
       include stdlib 

       $tenant_vrf_info_hiera   = hiera('vrfs')
       notify{"${tenant_vrf_info_hiera['l3_vni']}":}        
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-06 11:46:19 -0600

GregLarkin gravatar image

It appears that you need to iterate and dereference one more level in your data structure prior to your notify resource, e.g.:

$tenant_vrf_info_hiera   = hiera('vrfs')
$tenant_vrf_info_hiera.each |$context, $data| {
  $vni = $data['l3_vni']
  $rd = $data['rd']
  notify{"${context}: ${vni}":}
}

I did not test this, so YMMV, but I hope it illustrates the concept correctly.

edit flag offensive delete link more
0

answered 2016-01-07 07:52:39 -0600

Aleksandr Kushch gravatar image

updated 2016-01-07 07:55:09 -0600

Thank you Greg. That worked.

That prints both the context and the VNI data. I can also print individual variable data. This means I can finally pass these values to 'ciscocommandconfig' provider.

I have also changed my YAML format from:

vrfs:      
 vrf-evpn-tenant-2:   
   l3_vni: 20101
   rd: '2000:20101'     
 vrf-evpn-tenant-3:
   l3_vni: 20102 
   rd: '2000:20102'

To:

tenant_vrf_info:
    - { vrf_name: 'vrf-evpn-tenant-2', l3_vni: 20101, rd: '2000:20101'}
    - { vrf_name: 'vrf-evpn-tenant-3', l3_vni: 20102, rd: '2000:20102'}

I have a python script that prints the scaled content for my YAML file. It is much simpler to print one line in python than the first chunk YAML of code.

edit flag offensive delete link more

Comments

Great, glad to hear it!

GregLarkin gravatar imageGregLarkin ( 2016-01-07 10:47:19 -0600 )edit

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-01-06 00:28:09 -0600

Seen: 20,047 times

Last updated: Jan 07 '16