Skip to content

Commit 6f39267

Browse files
committed
Updates to playbook and roles for Ansible 2.9
1 parent 6579bc3 commit 6f39267

File tree

13 files changed

+166
-167
lines changed

13 files changed

+166
-167
lines changed

netdevops/ansible_part_3/network_deploy.yaml

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,28 @@
1010
---
1111
- name: Enable Model Driven Programmability (NETCONF) on IOS-XE
1212
hosts: iosxe
13-
connection: local
13+
14+
# Ansible added new connection options for networking devices
15+
# to replace connection: local
16+
# Now connection: network_cli or httpapi are recommended
17+
# Doc: https://docs.ansible.com/ansible/2.9/network/user_guide/platform_nxos.html
18+
connection: network_cli
1419
gather_facts: false
1520

1621
roles:
1722
- iosxe_mdp
1823

1924
- name: Enable NX-API on NX-OS
2025
hosts: nxos
21-
connection: local
26+
connection: network_cli
2227
gather_facts: false
2328

2429
roles:
2530
- nxos_nxapi
2631

2732
- name: Configure Network Core
2833
hosts: core
29-
connection: local
34+
connection: netconf
3035
gather_facts: false
3136

3237
roles:
@@ -35,7 +40,7 @@
3540

3641
- name: Configure Distribution Switches
3742
hosts: distribution
38-
connection: local
43+
connection: network_cli
3944
gather_facts: false
4045

4146
roles:
@@ -48,7 +53,7 @@
4853

4954
- name: Configure Access Switches
5055
hosts: access
51-
connection: local
56+
connection: network_cli
5257
gather_facts: false
5358

5459
roles:

netdevops/ansible_part_3/roles/iosxe_mdp/tasks/main.yaml

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
#
77
# Illustrate the following concepts:
88
# -
9+
#
10+
# Note: This file has been updated to leverage the network_cli
11+
# connection method. This is an update from the original
12+
# version which is used in videos.
913
##############################################################
1014
---
1115
- name: Configure NETCONF
1216
tags: [api, netconf]
1317
ios_config:
14-
provider:
15-
host: "{{inventory_hostname}}"
16-
timeout: 15
1718
lines:
19+
# Note: Due to problem with older IOS XE Self Signed certs expiring
20+
# on Jan 1, 2020, manually changing time on routers to allow certs
21+
# to remain valid.
22+
# Info: https://www.cisco.com/c/en/us/support/docs/security-vpn/public-key-infrastructure-pki/215118-ios-self-signed-certificate-expiration-o.html#anc9
23+
# This is only needed because Sandbox used has IOS XE 16.8.1a deployed.
24+
# newer CSR images would NOT need this fix.
25+
- do clock set 10:00:00 1 Dec 2019
1826
- netconf-yang
1927
- netconf-yang cisco-odm polling-enable
2028
# - restconf

netdevops/ansible_part_3/roles/netconf_l3_interfaces/tasks/main.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
---
1111
- name: "Generate NETCONF Interface config"
1212
tags: [api, netconf, layer3]
13-
with_items: "{{l3_interfaces}}"
13+
loop: "{{l3_interfaces}}"
1414
template:
1515
src: "files/ietf_interface_template.j2"
1616
dest: "./configs/{{inventory_hostname}}-{{item.interface_type}}{{item.interface_id}}.xml"
1717

1818
- name: Configure Interfaces with NETCONF
1919
tags: [api, netconf, layer3]
20-
with_items: "{{l3_interfaces}}"
20+
loop: "{{l3_interfaces}}"
21+
loop_control:
22+
pause: 2
2123
netconf_config:
2224
host: "{{inventory_hostname}}"
2325
hostkey_verify: false
24-
username: "{{lookup('env','ANSIBLE_NET_USERNAME')}}"
25-
password: "{{lookup('env','ANSIBLE_NET_PASSWORD')}}"
2626
src: "./configs/{{inventory_hostname}}-{{item.interface_type}}{{item.interface_id}}.xml"

netdevops/ansible_part_3/roles/netconf_ospf/files/ned_ospf.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<config>
2-
<native xmlns="http://cisco.com/ns/yang/ned/ios">
2+
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
33
<router>
4-
<ospf>
4+
<ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
55
<id>{{ ospf.process_id }}</id>
66
<router-id>{{ ospf_router_id }}</router-id>
77
{% for network in ospf_networks %}

netdevops/ansible_part_3/roles/netconf_ospf/tasks/main.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@
1919
netconf_config:
2020
host: "{{inventory_hostname}}"
2121
hostkey_verify: false
22-
username: "{{lookup('env','ANSIBLE_NET_USERNAME')}}"
23-
password: "{{lookup('env','ANSIBLE_NET_PASSWORD')}}"
2422
src: "./configs/{{inventory_hostname}}-ospf.xml"

netdevops/ansible_part_3/roles/nxos_hsrp/tasks/main.yaml

+2-10
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,16 @@
1010
---
1111
- name: Enable Features
1212
tags: [api, nxapi, hsrp]
13-
with_items:
13+
loop:
1414
- hsrp
1515
nxos_feature:
16-
provider:
17-
host: "{{inventory_hostname}}"
18-
transport: nxapi
19-
timeout: 15
2016
feature: "{{ item }}"
2117
state: enabled
2218

2319
- name: Configure HSRP
2420
tags: [api, nxapi, hsrp]
25-
with_items: "{{ hsrp_interfaces }}"
21+
loop: "{{ hsrp_interfaces }}"
2622
nxos_hsrp:
27-
provider:
28-
host: "{{inventory_hostname}}"
29-
transport: nxapi
30-
timeout: 15
3123
group: "{{ item.group }}"
3224
vip: "{{ item.vip }}"
3325
interface: "{{ item.interface }}"

netdevops/ansible_part_3/roles/nxos_l3_interfaces/tasks/main.yaml

+15-20
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,33 @@
1010
---
1111
- name: Enable Features
1212
tags: [api, nxapi, layer3]
13-
with_items:
13+
loop:
1414
- interface-vlan
1515
nxos_feature:
16-
provider:
17-
host: "{{inventory_hostname}}"
18-
transport: nxapi
19-
timeout: 15
2016
feature: "{{ item }}"
2117
state: enabled
2218

2319
- name: Configure Layer 3 Interfaces
2420
tags: [api, nxapi, layer3]
25-
with_items: "{{ l3_interfaces }}"
21+
loop: "{{ l3_interfaces }}"
22+
# Note: the nxos_interface module has been replaced with nxos_interfaces
23+
# and will be deprecated/removed soon. However the new nxos_interfaces
24+
# module has a bug in Ansible 2.9 when trying to create loopbacks or SVI.
25+
# Keeping this example using nxos_interface for now.
26+
# Info:
27+
# - https://docs.ansible.com/ansible/2.9/modules/nxos_interfaces_module.html
28+
# - https://docs.ansible.com/ansible/2.9/modules/nxos_interface_module.html
2629
nxos_interface:
27-
provider:
28-
host: "{{inventory_hostname}}"
29-
transport: nxapi
30-
timeout: 15
3130
interface: "{{ item.interface_type }}{{ item.interface_id }}"
3231
mode: layer3
3332
description: "{{ item.description }}"
3433
admin_state: up
3534

3635
- name: Configure IPv4 Address on Interface
3736
tags: [api, nxapi, layer3]
38-
with_items: "{{ l3_interfaces }}"
39-
nxos_ip_interface:
40-
provider:
41-
host: "{{inventory_hostname}}"
42-
transport: nxapi
43-
timeout: 15
44-
interface: "{{ item.interface_type }}{{ item.interface_id }}"
45-
version: v4
46-
addr: "{{ item.ip_address }}"
47-
mask: "{{ item.prefix }}"
37+
loop: "{{ l3_interfaces }}"
38+
nxos_l3_interfaces:
39+
config:
40+
- name: "{{ item.interface_type }}{{ item.interface_id }}"
41+
ipv4:
42+
- address: "{{ item.ip_address }}/{{ item.prefix }}"

netdevops/ansible_part_3/roles/nxos_nxapi/tasks/main.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@
88
# -
99
##############################################################
1010
---
11-
# - name: "Retrieving NX-OS Facts"
12-
# nxos_facts:
13-
# provider:
14-
# host: "{{inventory_hostname}}"
15-
# register: facts
16-
#
17-
# - name: "Print Facts"
18-
# debug: msg="{{facts}}"
19-
2011
- name: Enable NX-API
2112
tags: [api, nxapi]
2213
nxos_feature:
23-
provider:
24-
host: "{{inventory_hostname}}"
25-
timeout: 15
2614
feature: nxapi
2715
state: enabled

netdevops/ansible_part_3/roles/nxos_ospf/tasks/main.yaml

+2-14
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,22 @@
1010
---
1111
- name: Enable Features
1212
tags: [api, nxapi, ospf]
13-
with_items:
13+
loop:
1414
- ospf
1515
nxos_feature:
16-
provider:
17-
host: "{{inventory_hostname}}"
18-
transport: nxapi
19-
timeout: 15
2016
feature: "{{ item }}"
2117
state: enabled
2218

2319
- name: Configure OSPF
2420
tags: [api, nxapi, ospf]
2521
nxos_ospf:
26-
provider:
27-
host: "{{inventory_hostname}}"
28-
transport: nxapi
29-
timeout: 15
3022
ospf: "{{ ospf.process_id }}"
3123
state: present
3224

3325
- name: Configure OSPF Interfaces
3426
tags: [api, nxapi, ospf]
35-
with_items: "{{ ospf.networks }}"
27+
loop: "{{ ospf.networks }}"
3628
nxos_interface_ospf:
37-
provider:
38-
host: "{{inventory_hostname}}"
39-
transport: nxapi
40-
timeout: 15
4129
interface: "{{ item.interface }}"
4230
ospf: "{{ ospf.process_id }}"
4331
area: "{{ item.area }}"

netdevops/ansible_part_3/roles/nxos_po_trunks/tasks/main.yaml

+31-26
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,42 @@
1010
---
1111
- name: Enable Features
1212
tags: [api, nxapi, trunk, vlan]
13-
with_items:
13+
loop:
1414
- lacp
1515
nxos_feature:
16-
provider:
17-
host: "{{inventory_hostname}}"
18-
transport: nxapi
19-
timeout: 15
2016
feature: "{{ item }}"
2117
state: enabled
2218

2319
- name: Create Uplink Port Channel to Distribution
2420
tags: [api, nxapi, trunk, vlan]
25-
with_items: "{{ uplinks }}"
26-
nxos_portchannel:
27-
provider:
28-
host: "{{inventory_hostname}}"
29-
transport: nxapi
30-
timeout: 15
31-
group: "{{ item.port_channel_id }}"
32-
members: "{{ item.members }}"
33-
force: true
34-
mode: on
35-
state: present
21+
loop: "{{ uplinks }}"
22+
nxos_lag_interfaces:
23+
config:
24+
- name: "port-channel{{ item.port_channel_id }}"
25+
members:
26+
- member: "{{ item.members.0 }}"
27+
mode: active
28+
- member: "{{ item.members.1 }}"
29+
mode: active
30+
31+
- name: Make Port Channel Layer 2
32+
tags: [api, nxapi, vpc]
33+
loop: "{{ uplinks }}"
34+
nxos_interfaces:
35+
config:
36+
- name: "port-channel{{ item.port_channel_id }}"
37+
enabled: true
38+
mode: layer2
39+
40+
# BUG: The nxos_l2_interfaces module should be able to configure
41+
# an interface as a trunk. However testing showed it isn't working
42+
# in the current version of Ansible. Therefore the nxos_config module
43+
# is used here to configure correctly.
44+
- name: Configure Port Channel Trunk
45+
tags: [api, nxapi, vpc]
46+
loop: "{{ uplinks }}"
47+
nxos_config:
48+
lines:
49+
- switchport mode trunk
50+
parents: interface port-channel{{ item.port_channel_id }}
3651

37-
- name: Configure Uplink Port Channels as Trunk
38-
tags: [api, nxapi, trunk, vlan]
39-
with_items: "{{ uplinks }}"
40-
nxos_switchport:
41-
provider:
42-
host: "{{inventory_hostname}}"
43-
transport: nxapi
44-
timeout: 15
45-
interface: "po{{ item.port_channel_id }}"
46-
mode: trunk

netdevops/ansible_part_3/roles/nxos_vlans/tasks/main.yaml

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@
88
# -
99
##############################################################
1010
---
11+
# - name: Configure VLANs
12+
# tags: [api, nxapi, vlan]
13+
# loop: "{{ vlans }}"
14+
# nxos_vlan:
15+
# vlan_id: "{{ item.id }}"
16+
# name: "{{ item.name }}"
17+
1118
- name: Configure VLANs
1219
tags: [api, nxapi, vlan]
13-
with_items: "{{ vlans }}"
14-
nxos_vlan:
15-
provider:
16-
host: "{{inventory_hostname}}"
17-
transport: nxapi
18-
timeout: 15
19-
vlan_id: "{{ item.id }}"
20-
name: "{{ item.name }}"
20+
# Note: to stay consistent with the videos for the lesson, this playbook
21+
# uses the loop construct for configuring interfaces. The current module
22+
# does support multiple interfaces in one task execution, and that would
23+
# be a more efficient configuration.
24+
loop: "{{ vlans }}"
25+
# Note: the module nxos_vlan has been replaced with nxos_vlans in
26+
# recent versions of Ansible.
27+
nxos_vlans:
28+
config:
29+
- vlan_id: "{{ item.id }}"
30+
name: "{{ item.name }}"
31+

0 commit comments

Comments
 (0)