Shutting down and bringing back up a port or interface is a procedure that is routinely used to reinitialize it on a network device.
Outcomes
You should be able to:
Execute an ad hoc command that displays the current state of an interface.
Perform a play that shuts down an interface.
Perform a play that brings up an interface.
Perform a play that bounces an interface (shut/no shut).
Open a terminal window on the workstation VM and change to the ~/proj/ directory.
Execute an ad hoc command that displays the current state of interface eth6 on the leaf01 machine.
[student@workstation proj]$ansible -m vyos_command \>-a "commands='sh int eth eth6|grep ^eth6'" leaf01leaf01 | SUCCESS => { "changed": false, "stdout": [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ], "stdout_lines": [ [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ] ] }
Perform a play that shuts down eth6 on leaf01.
Compose a playbook named ifdown.yml with required extra variables named target and intf that shuts down the interface on the host.
[student@workstation proj]$cat ifdown.yml--- - name: play to shutdown an interface # Required arguments: target, intf hosts: "{{ target }}" tasks: - name: disable interface {{ intf }} on a VyOS box vyos_interface: name: "{{ intf }}" enabled: False when: ansible_network_os == 'vyos' - name: disable interface {{ intf }} on an IOS box ios_interface: name: "{{ intf }}" enabled: False when: ansible_network_os == 'ios'
Perform the play in the playbook.
[student@workstation proj]$ansible-playbook -e "target=leaf01 intf=eth6" \>ifdown.yml
Display the state of eth6 on leaf01 after performing the play.
[student@workstation proj]$ansible -m vyos_command \>-a "commands='sh int eth eth6|grep ^eth6'" leaf01leaf01 | SUCCESS => { "changed": false, "stdout": [ "eth6: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000" ], "stdout_lines": [ [ "eth6: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000" ] ] }
Perform a play that brings up interface eth6 on leaf01.
Compose a playbook named ifup.yml with required extra variables named target and intf that brings up the specified interface on the specified host.
[student@workstation proj]$cat ifup.yml--- - name: bring up an interface # Required arguments: target, intf hosts: "{{ target }}" tasks: - name: enable interface {{ intf }} on a VyOS box vyos_interface: name: "{{ intf }}" enabled: True when: ansible_network_os == 'vyos' - name: enable interface {{ intf }} on an IOS box ios_interface: name: "{{ intf }}" enabled: True when: ansible_network_os == 'ios'
Perform the play in the playbook.
[student@workstation proj]$ansible-playbook -e "target=leaf01 intf=eth6" \>ifup.yml
Display the state of eth6 on leaf01 after performing the play.
[student@workstation proj]$ansible -m vyos_command \>-a "commands='sh int eth eth6|grep ^eth6'" leaf01leaf01 | SUCCESS => { "changed": false, "stdout": [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ], "stdout_lines": [ [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ] ] }
Perform a play that bounces an interface.
Compose a playbook named bounce-if.yml containing a play that first shuts down an interface, then brings it up.
[student@workstation proj]$cat bounce-if.yml--- - name: bounce an interface (shut/no shut) # Required arguments: target, intf hosts: "{{ target }}" tasks: - name: shut interface {{ intf }} on a VyOS box vyos_interface: name: "{{ intf }}" enabled: False when: target in groups['vyos'] - name: shut interface {{ intf }} on an IOS box ios_interface: name: "{{ intf }}" enabled: False when: target in groups['ios'] - name: pause briefly before enabling interfaces pause: seconds: 1 - name: enable interface {{ intf }} on a VyOS box vyos_interface: name: "{{ intf }}" enabled: True when: target in groups['vyos'] - name: enable interface {{ intf }} on an IOS box ios_interface: name: "{{ intf }}" enabled: True when: target in groups['ios']
Check the playbook's syntax, then perform its play, applying it to the eth6 interface on leaf01.
[student@workstation proj]$ansible-playbook -e "target=leaf01 intf=eth6" \>--syntax-check bounce-if.ymlPlaybook: bounce-if.yml[student@workstation proj]$ansible-playbook -e "target=leaf01 intf=eth6" \>bounce-if.ymlPLAY [bounce an interface (shut/no shut)] ************************************** TASK [shut interface eth6 on a VyOS box] *************************************** changed: [leaf01] TASK [shut interface eth6 on an IOS box] *************************************** skipping: [leaf01] TASK [pause briefly before enabling interfaces] ******************************** Pausing for 1 seconds (ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort) ok: [leaf01] TASK [enable interface eth6 on a VyOS box] ************************************** changed: [leaf01] TASK [enable interface eth6 on an IOS box] ************************************* skipping: [leaf01] PLAY RECAP ********************************************************************* leaf01 : ok=3 changed=2 unreachable=0 failed=0
Display the state of eth6 on leaf01 after performing the play.
[student@workstation proj]$ansible -m vyos_command \>-a "commands='sh int eth eth6|grep ^eth6'" leaf01leaf01 | SUCCESS => { "changed": false, "stdout": [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ], "stdout_lines": [ [ "eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000" ] ] }
This concludes the guided exercise.