Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 158cc38

Browse files
committedJan 14, 2021
Updates for Ansible 2.9
1 parent 6ce7ef2 commit 158cc38

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed
 

‎netdevops/ansible_part_2/example1.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
---
1212
- name: Retrieve facts from Switches
1313
hosts: switches
14-
connection: local
14+
gather_facts: False
15+
16+
# Ansible added new connection options for networking devices
17+
# to replace connection: local
18+
# Now connection: network_cli or httpapi are recommended
19+
# Doc: https://docs.ansible.com/ansible/2.9/network/user_guide/platform_nxos.html
20+
connection: network_cli
1521

1622
tasks:
1723
- name: "Retrieving NX-OS Facts"
1824
nxos_facts:
19-
host: "{{inventory_hostname}}"
20-
transport: nxapi
25+
# See docs for what subset options of facts are available
26+
# https://docs.ansible.com/ansible/2.9/modules/nxos_facts_module.html#nxos-facts-module
27+
gather_subset: all
2128
register: nxos_info
2229

2330
- name: "Print NX-OS Facts"

‎netdevops/ansible_part_2/example2.yaml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,49 @@
1111
---
1212
- name: Configure Loopback Networks on Each Switch
1313
hosts: switches
14-
connection: local
14+
gather_facts: False
15+
16+
# Ansible added new connection options for networking devices
17+
# to replace connection: local
18+
# Now connection: network_cli or httpapi are recommended
19+
# Doc: https://docs.ansible.com/ansible/2.9/network/user_guide/platform_nxos.html
20+
connection: network_cli
1521

1622
tasks:
1723
- name: Create Loopback Interface
18-
with_items: "{{ local_loopbacks }}"
24+
# Note: The "with_items" syntax has been replaced by "loop"
25+
# - https://docs.ansible.com/ansible/2.9/user_guide/playbooks_loops.html#with-items
26+
loop: "{{ local_loopbacks }}"
27+
# with_items: "{{ l3_fabric.interfaces }}"
28+
# Note: the nxos_interface module has been replaced with nxos_interfaces
29+
# and will be deprecated/removed soon. However the new nxos_interfaces
30+
# module has a bug in Ansible 2.9 when trying to create loopbacks. Keeping
31+
# this example using nxos_interface for now.
32+
# Info:
33+
# - https://docs.ansible.com/ansible/2.9/modules/nxos_interfaces_module.html
34+
# - https://docs.ansible.com/ansible/2.9/modules/nxos_interface_module.html
1935
nxos_interface:
20-
host: "{{ inventory_hostname }}"
2136
interface: "{{ item.name }}"
2237
mode: layer3
2338
description: "{{ item.desc }}"
24-
admin_state: up
2539

40+
41+
42+
# Note: The module nxos_ip_interface was obsoleted by Ansible and replaced with
43+
# nxos_l3_interfaces. This module provides the same purpose, but with different
44+
# syntax. See details at:
45+
# - https://docs.ansible.com/ansible/2.9/modules/nxos_l3_interfaces_module.html
2646
- name: Configure IPv4 Address on Interface
27-
with_items: "{{ local_loopbacks }}"
28-
nxos_ip_interface:
29-
host: "{{ inventory_hostname }}"
30-
state: present
31-
interface: "{{ item.name }}"
32-
version: v4
33-
addr: "{{ item.ip_address }}"
34-
mask: "{{ item.prefix }}"
47+
# Note: The "with_items" syntax has been replaced by "loop"
48+
# - https://docs.ansible.com/ansible/2.9/user_guide/playbooks_loops.html#with-items
49+
loop: "{{ local_loopbacks }}"
50+
# Note: to stay consistent with the videos for the lesson, this playbook
51+
# uses the loop construct for configuring interfaces. The current module
52+
# does support multiple interfaces in one task execution, and that would
53+
# be a more efficient configuration.
54+
nxos_l3_interfaces:
55+
state: merged
56+
config:
57+
- name: "{{ item.name }}"
58+
ipv4:
59+
- address: "{{ item.ip_address }}/{{ item.prefix }}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These variables are used with the connection: network_cli for Ansible
2+
# Info: https://docs.ansible.com/ansible/2.9/network/user_guide/platform_nxos.html
3+
# https://docs.ansible.com/ansible/2.9/plugins/connection/network_cli.html
4+
5+
---
6+
# ansible_connection: network_cli
7+
ansible_network_os: nxos
8+
ansible_user: cisco
9+
ansible_password: cisco
10+
ansible_become: yes
11+
ansible_become_method: enable
12+
ansible_become_password: cisco

0 commit comments

Comments
 (0)
Please sign in to comment.