Hello,
I'm looking for some guidance on what's the best way to setup my jinja2 .j2 
template so I can generate my VLAN's correctly in a template.  I would like to 
setup my host_vars file like the following:



# bmc.yml 
https://github.com/ebmarquez/poc/blob/master/Ansible/cisco/nexus/hosts_vars/BMC.yml

---

VLAN:

  ID: 12

  NAME: "TEST1"

  SHUTDOWN: False

  INTERFACE:

    SHUTDOWN: False

    DESC: "Test 123"

    IPV4:

      ADDRESS: "192.168.1.1/24"

VLAN:

  ID: 13

  NAME: "test2"

  SHUTDOWN: True

  INTERFACE:

    SHUTDOWN: True

    DESC: "test2 456"

    IPV4:

      ADDRESS: "10.1.2.3/30"



.j2 template

{{#

########################################

Purpose:

Create a Switch Virtual Interface (SVI)



Required Variables and Types

VLAN.ID (int)

VLAN.SHUTDOWN (boolean)

VLAN.INTERFACE.DESC (string)

VLAN.INTERFACE.SHUTDOWN (boolean)

VLAN.INTERFACE_IPV4_ADDRESS (string)

########################################

#}}



feature interface-vlan



Vlan{{ VLAN.ID }}

  name {{ VLAN.NAME }}

  state active

{% if VLAN.SHUTDOWN %}

  shutdown

{% else %}

  no shutdown

{% endif %}



interface Vlan{{ VLAN.ID }}

  Description {{ VLAN.INTERFACE.DESC }}

{% if VLAN.INTERFACE.SHUTDOWN %}

  shutdown

{% else %}

  no shutdown

{% endif %}

  ip address {{ VLAN.INTERFACE.IPV4.ADDRESS }}


I seem to be missing how to setup my template file so I can take advantage of 
this format.  I would like to have the for loop understand that I have multiple 
vlan's groups and pass in the reference for that instance it's on.  I'm fairly 
new to Ansible so some help from the larger group would be useful.  I checked 
in my file to github so you can see what the file look like.



Role Task file:

https://github.com/ebmarquez/poc/blob/master/Ansible/cisco/nexus/roles/bmc/Tasks/main.yml



Site.yml file

https://github.com/ebmarquez/poc/blob/master/Ansible/cisco/nexus/site.yml


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/DM2PR0301MB1261CFDBC69AADB3BFDC3DDADD640%40DM2PR0301MB1261.namprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to