Skip to main content

Jinja2

Jag är inte bra på Jinja2. Här är vad jag har samlat på mig hittils.

Om man konfigurerar statiska rutter med Ansible kan man använda sig av jinja2-templates för att enbart ha med next-hop om det faktiskt finns definierat i inventory. Se exempel:

- name: Configure static routes
  cisco.ios.ios_config:
    lines:
      - "ip route {{ item.name }} {{ item.interface }}{% if item.next_hop is defined %} {{ item.next_hop }}{% endif %}"
  when: static_routes is defined
  loop: "{{ static_routes }}"

! Inventory/host_vars. Första exemplet med next hop och andra utan.
static_routes:
  - name:  8.8.4.4 255.255.255.255
    interface: GigabitEthernet0/0/0
    next_hop: 1.1.1.1
  - name: 8.8.4.4 255.255.255.255
    interface: GigabitEthernet0/1/0.2