Friday, April 24, 2020

Configure Zero Touch Provisioning on IOSXE with tftp boot

ZTP with TFTP server running on Ubuntu VM
1.     The following is a sample DHCP server configuration with TFTP server details. This server is connected either to the management port or front panel port of a switch. This DHCP server is running on a Linux Ubuntu VM.

CODE SNIPPET
 cisco@U-Desk:~$ more /etc/dhcp/dhcpd.conf 

 subnet 172.26.198.0 netmask 255.255.255.0 {
 range 172.26.198.35 172.26.198.36;
     host catalyst_switch {
         fixed-address           172.26.198.35 ;
         hardware ethernet       50:67:ae:1d:c8:80;
         option bootfile-name    "ZTP_python.py";
         option tftp-server-name "172.266.198.44";
     }
 }
In this configuration we are assigning the IP address of an interface as “172.26.198.35” for the mac address “50:67:ae:1d:c8:80”. The name of the python script to download is “ZTP_python.py” from the TFTP server “172.266.198.44”. In this scenario, TFTP and DHCP servers are running on the same VM.

2.     Check the status of the DHCP server using the command “service isc-dhcp-server status”. If it is not “active (running)”, then start the DHCP server using the command “sudo service isc-dhcp-server start”.
CODE SNIPPET
 cisco@U-Desk:~$ sudo service isc-dhcp-server start
 cisco@U-Desk:~$

 cisco@U-Desk:~$ service isc-dhcp-server status
 ● isc-dhcp-server.service - ISC DHCP IPv4 server
    Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2017-12-08 05:25:04 PST; 1 weeks 2 days ago
 <removed the lines>

3.     The following is a sample Python script created in TFTP server. It configures loopback interface 100 and then executes some show commands.

CODE SNIPPET
 cisco@U-Desk:/var/lib/tftpboot$ more ZTP_python.py

 print "\n\n *** Sample ZTP Day0 Python Script *** \n\n"

 # Importing cli module
 import cli

 print "\n\n *** Executing show version *** \n\n"
 cli.executep('show version')

 print "\n\n *** Configuring a Loopback Interface *** \n\n"
 cli.configurep(["interface loop 100", "ip address 10.10.10.10 255.255.255.255", "end"])

 print "\n\n *** Executing show ip interface brief *** \n\n"
 cli.executep('show ip int brief')

 print "\n\n *** ZTP Day0 Python Script Execution Complete *** \n\n"

4.     Check the status of the TFTP server by using the command “service tftpd-hpa status". If it is not “active (running)” then start the TFTP server using the “sudo service tftpd-hpa start” command.
     
    
     CODE SNIPPET
 cisco@U-Desk:/var/lib/tftpboot$ sudo service tftpd-hpa start
 cisco@U-Desk:/var/lib/tftpboot$

 cisco@U-Desk:/var/lib/tftpboot$ service tftpd-hpa status
 ● tftpd-hpa.service - LSB: HPA's tftp server
    Loaded: loaded (/etc/init.d/tftpd-hpa; bad; vendor preset: enabled)
    Active: active (running) since Mon 2017-12-18 05:46:10 PST; 1s ago
 <removed the lines>

5.     When a device that supports Zero-Touch Provisioning boots up, and does not find the startup configuration, the device enters the Zero-Touch Provisioning mode. The following sample Zero-Touch Provisioning boot log displays that Guest Shell is successfully enabled, the Python script is downloaded to the Guest Shell, and the Guest Shell executes the downloaded Python script and configures the device for Day Zero.
     
     CODE SNIPPET
 % failed to initialize nvram
 % attempting to recover from backup
 % failed to initialize backup nvram

          --- System Configuration Dialog ---

 Would you like to enter the initial configuration dialog? [yes/no]:
 The process for the command is not responding or is otherwise unavailable
 The process for the command is not responding or is otherwise unavailable
 The process for the command is not responding or is otherwise unavailable
 The process for the command is not responding or is otherwise unavailable
 The process for the command is not responding or is otherwise unavailable
 The process for the command is not responding or is otherwise unavailable
 Guestshell enabled successfully

  *** Sample ZTP Day0 Python Script ***

  *** Executing show version ***

 <removed the lines>

 Switch Ports Model              SW Version        SW Image              Mode
 ------ ----- -----              ----------        ----------            ----
 *    1 62    WS-C3850-12X48U    16.6.1            CAT3K_CAA-UNIVERSALK9 BUNDLE
 Configuration register is 0x102

  *** Configuring a Loopback Interface ***

 Line 1 SUCCESS: interface loop 100
 Line 2 SUCCESS: ip address 10.10.10.10 255.255.255.255
 Line 3 SUCCESS: end

  *** Executing show ip interface brief ***

 <removed the lines>

 Any interface listed with OK? value "NO" does not have a valid configuration
 Te1/1/8                unassigned      YES unset  down                  down
 Fo1/1/1                unassigned      YES unset  down                  down
 Fo1/1/2                unassigned      YES unset  down                  down
 Loopback100            10.10.10.10     YES TFTP   up                    up

  *** ZTP Day0 Python Script Execution Complete ***

 Press RETURN to get started!
6.     ZTP process using TFTP server is now completed and the IOS prompt is accessible.


shared from:https://developer.cisco.com/docs/ios-xe/#!zero-touch-provisioning/ztp-with-http-server-running-on-ubuntu-vm