Skip to content

Instantly share code, notes, and snippets.

@LukeDRussell
Created April 16, 2016 07:43
Show Gist options
  • Save LukeDRussell/47fa117b9664c38021054216f6d66b3f to your computer and use it in GitHub Desktop.
Save LukeDRussell/47fa117b9664c38021054216f6d66b3f to your computer and use it in GitHub Desktop.
ios_template making changes when router config already exists
#!/usr/bin/env ansible-playbook
- name: Deploy DMVPN tunnels
hosts: dmvpn
gather_facts: no
connection: local
vars_files:
- vpn_vars.yml
roles:
- deploy_tunnel
- name: Deploy tunnels to class 1 routers
ios_template:
src: class1_r1.j2
provider: "{{ cli }}"
- name: "Include {{ dev_role }} tasks"
include: "{{ item }}"
with_first_found:
- files: "{{ dev_role }}.yml"
skip: true
paths: tasks
{% for vpns in router_vpns %}
!
interface Tunnel{{ VPN[vpns]['pri_tunnel'] }}
description {{ vpns }} primary tunnel
ip vrf forwarding {{ vpns }}
ip address {{ ip.pri_tunnel }} {{ dmvpn_mask }}
no ip redirects
ip mtu 1400
ip nhrp authentication {{ VPN[vpns]['pri_tunnel'] }}
ip nhrp map multicast {{ ip.pri_hub_loopback }}
ip nhrp map {{ ip.pri_hub_tunnel }} {{ ip.pri_hub_loopback }}
ip nhrp network-id {{ VPN[vpns]['pri_tunnel'] }}
ip nhrp holdtime 360
ip nhrp nhs {{ ip.pri_hub_tunnel }}
ip nhrp shortcut
ip tcp adjust-mss 1360
load-interval 30
delay {{ pri_delay }}
qos pre-classify
{% if vpns == primary_customer %}
tunnel source Loopback1
{% else %}
tunnel source Loopback2
{% endif %}
tunnel mode gre multipoint
tunnel key {{ VPN[vpns]['pri_tunnel'] }}
interface Tunnel{{ VPN[vpns]['sec_tunnel'] }}
description {{ vpns }} primary tunnel
ip vrf forwarding {{ vpns }}
ip address {{ ip.sec_tunnel }} {{ dmvpn_mask }}
no ip redirects
ip mtu 1400
ip nhrp authentication {{ VPN[vpns]['sec_tunnel'] }}
ip nhrp map multicast {{ ip.sec_hub_loopback }}
ip nhrp map {{ ip.sec_hub_tunnel }} {{ ip.sec_hub_loopback }}
ip nhrp network-id {{ VPN[vpns]['sec_tunnel'] }}
ip nhrp holdtime 360
ip nhrp nhs {{ ip.sec_hub_tunnel }}
ip nhrp shortcut
ip tcp adjust-mss 1360
load-interval 30
delay {{ sec_delay }}
qos pre-classify
{% if vpns == primary_customer %}
tunnel source Loopback3
{% else %}
tunnel source Loopback4
{% endif %}
tunnel mode gre multipoint
tunnel key {{ VPN[vpns]['sec_tunnel'] }}
{% endfor %}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment