ios_static_route idempotence fix (#35912)

* Remove default admin_distance and fix the idempotence thereof

Fixes #33290

* Fix tests and use yaml anchors to shorten tests

* Add test for undefined admin_distance

* Read config from `show run` if `show ip static route` fails

* Restore flags to ios.get_config &  use get_config where appropriate
This commit is contained in:
Nathaniel Case 2018-03-05 09:28:37 -05:00 committed by GitHub
commit 7016b3b9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 121 additions and 87 deletions

View file

@ -1,15 +1,17 @@
---
- debug: msg="START ios cli/ios_static_route.yaml on connection={{ ansible_connection }}"
- name: delete static route - setup
net_static_route:
prefix: 172.16.31.0
- name: Clear all static routes
ios_static_route: &delete_all
aggregate:
- { prefix: 172.16.31.0 }
- { prefix: 172.16.32.0 }
- { prefix: 172.16.33.0 }
- { prefix: 172.16.34.0 }
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 1
state: absent
provider: "{{ cli }}"
register: result
- name: create static route
ios_static_route:
@ -23,13 +25,14 @@
- assert:
that:
- 'result.changed == true'
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 1"]'
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8"]'
- name: create static route again (idempotent)
- name: Verify idempotence with default admin_distance
ios_static_route:
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 1
state: present
provider: "{{ cli }}"
register: result
@ -39,7 +42,7 @@
- 'result.changed == false'
- name: modify admin distance of static route
ios_static_route:
ios_static_route: &admin2
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
@ -54,11 +57,18 @@
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 2"]'
- name: modify admin distance of static route again (idempotent)
ios_static_route: *admin2
register: result
- assert:
that:
- 'result.changed == false'
- name: Verify idempotence with unspecified admin_distance
ios_static_route:
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 2
state: present
provider: "{{ cli }}"
register: result
@ -68,11 +78,10 @@
- 'result.changed == false'
- name: delete static route
ios_static_route:
ios_static_route: &delete
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 2
state: absent
provider: "{{ cli }}"
register: result
@ -83,13 +92,7 @@
- 'result.commands == ["no ip route 172.16.31.0 255.255.255.0 10.0.0.8"]'
- name: delete static route again (idempotent)
ios_static_route:
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 2
state: absent
provider: "{{ cli }}"
ios_static_route: *delete
register: result
- assert:
@ -99,8 +102,10 @@
- name: Add static route aggregates
ios_static_route:
aggregate:
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.32.0 }
- { prefix: 172.16.33.0 }
mask: 255.255.255.0
next_hop: 10.0.0.8
state: present
provider: "{{ cli }}"
register: result
@ -108,14 +113,16 @@
- assert:
that:
- 'result.changed == true'
- 'result.commands == ["ip route 172.16.32.0 255.255.255.0 10.0.0.8 1", "ip route 172.16.33.0 255.255.255.0 10.0.0.8 1"]'
- 'result.commands == ["ip route 172.16.32.0 255.255.255.0 10.0.0.8", "ip route 172.16.33.0 255.255.255.0 10.0.0.8"]'
- name: Add and remove static route aggregates with overrides
ios_static_route:
aggregate:
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8, state: absent }
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.32.0 }
- { prefix: 172.16.33.0, state: absent }
- { prefix: 172.16.34.0 }
mask: 255.255.255.0
next_hop: 10.0.0.8
state: present
provider: "{{ cli }}"
register: result
@ -123,16 +130,10 @@
- assert:
that:
- 'result.changed == true'
- 'result.commands == ["no ip route 172.16.33.0 255.255.255.0 10.0.0.8", "ip route 172.16.34.0 255.255.255.0 10.0.0.8 1"]'
- 'result.commands == ["no ip route 172.16.33.0 255.255.255.0 10.0.0.8", "ip route 172.16.34.0 255.255.255.0 10.0.0.8"]'
- name: Remove static route aggregates
ios_static_route:
aggregate:
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
state: absent
provider: "{{ cli }}"
ios_static_route: *delete_all
register: result
- assert:

View file

@ -5,20 +5,19 @@
# implementation module and module run is successful.
- name: delete static route - setup
net_static_route:
net_static_route: &delete
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 1
state: absent
provider: "{{ cli }}"
register: result
- name: create static route using platform agnostic module
net_static_route:
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 1
state: present
provider: "{{ cli }}"
register: result
@ -29,13 +28,6 @@
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 1"]'
- name: delete static route - teardown
net_static_route:
prefix: 172.16.31.0
mask: 255.255.255.0
next_hop: 10.0.0.8
admin_distance: 2
state: absent
provider: "{{ cli }}"
register: result
net_static_route: *delete
- debug: msg="END ios cli/net_static_route.yaml on connection={{ ansible_connection }}"