So you are interested in leveraging Ansible for configuration management of your NX-OS devices and are kicking the tires using the Open NX-OS Sandbox. Well, you are in the right place!
Here you will find some sample playbooks to deploy common configurations and topologies that are all ready to run against the Sandbox. Just clone down the repository and jump right in.
- Code and Ansible Setup
- Sample Topologies and Configs
- Basic Layer 3 Fabric
- Basic Layer 2 Fabric - Coming Soon!
- Switch Admin Tasks
Before you can run your first playbook, you need to:
- Reserve and connect to a Sandbox
- Download/clone the sample code repository
- Setup your workstation for Ansible.
The simplest way to get the code is to just git clone
it to your local machine.
# from the directory where you want to put the code
git clone https://github.com/DevNetSandbox/sbx_nxos
cd sbx_nxos
If you'd like to get your very own copy of the repository that you can update or add code to, you may want to "Fork" the repo and clone down your own copy. And please submit Pull Requests for anything cool you build in the Sandbox!
If you'd rather just download the code without mucking around with git
, you can do that too. Just hit this link to download a zip file with the code: DevNetSandbox/sbx_nxos/archive/master.zip
Ansible is written in Python which means you set it up using the same steps as any Python application. Like other Python projects, we highly recommend leveraging Virtual Environments with Ansible for the best experience. Also, Ansible is currently only fully supported with Python 2.7, Python 3 support is in "preview".
Follow these steps to create a virtual environment and install the requirements.
# Here we explicitly create the venv with Python 2.7
virtualenv venv --python=python2.7
source venv/bin/activate
pip install -r requirements.txt
Now Ansible is installed and ready to go. One last step before running any of the sample playbooks is to tell Ansible about the target hosts in the sandbox, and the credentials to use to access.
For the hosts part, included in the directory is ansible.cfg
(see it here). This is a standard Ansible file that identifies the default location of the inventory. By including the file within the directory, Ansible will use the hosts file located within the repo.
For the credentials, simply run this command to set a series of local environment variables for Ansible to use. See the file here: .ansible_env
source .ansible_env
Here is a list of the different topologies and configuration details.
- Basic Layer 3 Fabric
- This is a sample network configuration that deploys Layer 3 (routed) links between all the switches in the topology along with routing protocol (OSPF and/or BGP)
Within the basic_l3_network folder are a series of Ansible Playbooks that will configure the Sandbox for a Basic Layer 3 Fabric with either OSPF or eBGP as the routing protocol.
- Point to Point Routed Links are /30s from 172.17.0.0/24
- Each switch has 4 Loopbacks configured for route injection
The playbooks in this configuration leverage details such as interfaces to configure, IP addresses, and routing protocol details that are stored in group and host variables. You can find these details within the following folders.
- host_vars: A file for each switch contains host specific details
- group_vars: The
all.yml
file contains details available for any host
- full_ospf.yml
- Fully deploy an OSPF network by running the following in this order
- full_bgp.yml
- Fully deploy an BGP network by running the following in this order
- full_remove.yml
- Fully remove the configuration by running the following in this order
- l3_fabric_ip_addresses.yml
- Deploy the Point to Point IP addresses on all the switches
- l3_fabric_ip_addresses_remove.yml
- Remove the Point to Point IP addresses on all the switches
- local_loopback_networks.yml
- Deploy local loopbacks onto all the switches
- local_loopback_networks_remove.yml
- Remove the local loopbacks from all the switches
- l3_fabric_ospf_routing.yml
- Deploy OSPF as the routing protocol to all switches
- Requires that the following playbooks have run
- l3_fabric_ospf_routing_remove.yml
- Remove OSPF from all switches
- l3_fabric_bgp_routing.yml
- Deploy eBGP as the routing protocol to all the switches
- Requires that the following playbooks have run
- l3_fabric_bgp_routing_remove.yml
- Remove BGP from all switches
To deploy the configuration to the Sandbox follow these steps.
# from the sbx-nxos directory
# activate the venv
source venv/bin/activate
# source the switch credentials
source .ansible_env
# enter the playbook directory
cd ansible-playbooks
# run the full deploy playbook
ansible-playbook basic_l3_network/full_ospf.yml
# from the sbx-nxos directory
# activate the venv
source venv/bin/activate
# source the switch credentials
source .ansible_env
# enter the playbook directory
cd ansible-playbooks
# run the full deploy playbook
ansible-playbook basic_l3_network/full_bpg.yml
# from the sbx-nxos directory
# activate the venv
source venv/bin/activate
# source the switch credentials
source .ansible_env
# enter the playbook directory
cd ansible-playbooks
# run the playbook of choice
ansible-playbook basic_l3_network/<PLAYBOOK.yml>
# from the sbx-nxos directory
# activate the venv
source venv/bin/activate
# source the switch credentials
source .ansible_env
# enter the playbook directory
cd ansible-playbooks
# run the full remove playbook
ansible-playbook basic_l3_network/full_remove.yml
Coming Soon!
Here are some basic switch administration playbooks included. Some of these are actually used as part of the Sandbox preparation tasks.
The playbook switch_admin/set_boot_image.yml sets the boot nxos
configuration on the switches using the nxos_config
module.
This playbook is leveraged as part of the Sandbox setup process to ensure the switches reload successfully should you restart them during testing.
To execute the playbook:
# from the sbx-nxos directory
# activate the venv
source venv/bin/activate
# source the switch credentials
source .ansible_env
# enter the playbook directory
cd ansible-playbooks
# run the full remove playbook
ansible-playbook switch_admin/set_boot_image.yml