This playbook automates the deployment of a Docker Container to a Nexus 9000 switch using Ansible. The primary Ansible collection used in this playbook is Cisco.Nxos, and the playbook follows the Docker Deployment instructions detailed here.
The working example deploys the perfSONAR container, but the playbook can easily be modified to deploy a different container.
A high level overview of deployment steps:
Note: Some containers are too large for the initial docker disk image partition (ex: perfSONAR). This playbook includes resizing the partition following the Resizing the Docker Storage Backend
section of the guide if necessary.
IMPORTANT: Resizing can lead to docker partition corruption. It's highly recommended to deploy a docker container manually to a switch, determine if a resize is necessary, and determine the proper amount to increase the partition by (assuming switches of the same hardware specs across switches).
This project follows Ansible best practices (Roles, Variable groupings, etc.). For a detailed guide on project structure and components (plus addtional examples of NX-OS Ansible Automation), refer to this guide.
git clone [repository name]
inventory_sample
file to inventory
.inventory
file.# inventory file for Ansible playbook
[nxos]
X.X.X.X
Y.Y.Y.Y
Note: It's assumed each switch is reachable via an SSH connection.
roles/nxos/vars/main.yml
. These credentials will be used for authentication to all switches specified in inventory
.--- # Global Variables for NXOS Playbook ansible_connection: ansible.netcommon.network_cli ansible_network_os: cisco.nxos.nxos ansible_user: <nx_os_ssh_user_username> ansible_password: <nx_os_ssh_user_password>
group_vars/all
. Default values are already set.Other Docker Container parameters can be specified by modifying the raw CLI docker commands found in roles/nxos/tasks/main.yml
---
# Docker specific variables
image_name: perfsonar/testpoint
network_type: host
# Enter a numeric value followed by an MB or GB
truncate_increase: 5GB
pip3 install -r requirements.txt
(this will install Ansible via pip
)To run the playbook, use the command:
$ ansible-playbook -i inventory app_deploy.yml --extra-vars "option=<option>"
where <option>
has 2 possible values:
check
(default): Runs show commands to check current Docker Images installed as well as running containersdeploy
: Runs main workflow, downloads Docker Image and spins up a Docker ContainerThe main playbook content is located at: roles/nxos/tasks/main.yml
(this is where the raw commands and modules can be found). While the playbook runs, task outputs show the raw command output throughout the process.
This example run shows deploying the perfSONAR container on 2 switches, one with enough space and one which requires resizing.
Before Running the Playbook:
Playbook Output:
After Running the Playbook:
Provided under Cisco Sample Code License, for details see LICENSE
Our code of conduct is available here
See our contributing guidelines here
Please note: This script is meant for demo purposes only. All tools/ scripts in this repo are released for use "AS IS" without any warranties of any kind, including, but not limited to their installation, use, or performance. Any use of these scripts and tools is at your own risk. There is no guarantee that they have been through thorough testing in a comparable environment and we are not responsible for any damage or data loss incurred with their use.
You are responsible for reviewing and testing any scripts you run thoroughly before use in any non-testing environment.
Owner
Contributors
Categories
Products
NX-OSProgramming Languages
License
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community