Created
March 24, 2024 17:42
-
-
Save platu/7ee29ec4174484e41cbca694bc680d3e to your computer and use it in GitHub Desktop.
IaC Lab 3 virtual routers network configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: CONFIGURE ROUTER INTERFACES AND DEFAULT ROUTES | |
hosts: routers | |
# Base topology configuration tasks for the three routers | |
tasks: | |
- name: APPLY HOSTNAME | |
cisco.ios.ios_hostname: | |
config: | |
hostname: "{{ inventory_hostname }}" | |
state: replaced | |
- name: APPLY INTERFACES BASE CONFIGURATION | |
cisco.ios.ios_interfaces: | |
config: | |
- name: "{{ item.interface_type }}{{ item.interface_id | string }}" | |
description: "{{ item.description }}" | |
enabled: "{{ item.enabled }}" | |
state: replaced | |
with_items: "{{ interfaces }}" | |
- name: APPLY INTERFACES L3 CONFIGURATION | |
cisco.ios.ios_l3_interfaces: | |
config: | |
- name: "{{ item.interface_type }}{{ item.interface_id | string }}" | |
ipv4: | |
- address: "{{ item.ipv4_address }}" | |
ipv6: | |
- address: "{{ item.ipv6_address }}" | |
state: replaced | |
when: item.ipv4_address is defined and item.ipv6_address is defined | |
with_items: "{{ interfaces }}" | |
# It may be useful to delete any existing entries before applying the | |
# default routes, as the replace state does not delete previous entries. | |
# - name: DELETE ALL STATIC ROUTES | |
# cisco.ios.ios_static_routes: | |
# state: deleted | |
# when: default_routes is defined | |
- name: APPLY DEFAULT ROUTES | |
cisco.ios.ios_static_routes: | |
config: | |
- address_families: | |
- afi: ipv4 | |
routes: | |
- dest: 0.0.0.0/0 | |
next_hops: | |
- forward_router_address: "{{ default_routes.ipv4_next_hop }}" | |
- afi: ipv6 | |
routes: | |
- dest: ::/0 | |
next_hops: | |
- forward_router_address: "{{ default_routes.ipv6_next_hop }}" | |
state: replaced | |
when: default_routes is defined | |
- name: CHECK IPV4 AND IPV6 DEFAULT ROUTE | |
cisco.ios.ios_ping: | |
dest: "{{ item.dest }}" | |
afi: "{{ item.afi }}" | |
count: 10 | |
state: present | |
register: result | |
when: default_routes is defined | |
failed_when: result.packet_loss | int > 10 | |
with_items: | |
- { dest: 9.9.9.9, afi: ip } | |
- { dest: 2620:fe::fe, afi: ipv6 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment