← Back to Engineering Blog
πŸ—“οΈ Oct 1, 2021⏱️ 2 min read

Zero-Touch Pod Decommissioning: Automated Teardown via Ansible & NSX-T API

How we automated the complete teardown and reclamation of vSphere tenant pods, unbinding DFW rules, Tier-1 gateways, and IPAM subnets in 45 seconds.

πŸŽ™οΈ Listen to ArticleREADY
AI Audio Synthesis Narrator
Share Post:

β€œAutomating infrastructure deployment is only half the battle β€” true cloud agility requires zero-touch automated decommissioning to prevent resource sprawl.”

The Setup

In October 2021 at NTT Data, our private cloud automation platform managed short-lived staging and QA pods for enterprise software clients. Hundreds of temporary vSphere tenant pods were provisioned weekly.

While deployment was automated via Ansible Tower, decommissioning remained a manual 15-step checklist.


The Mess

Engineers frequently delayed or forgot manual teardown steps when client testing completed:

  • Abandoned Tier-1 Gateways and segment ports remained active in NSX-T Manager.
  • Unused IP subnets sat locked in IPAM, triggering artificial IP space exhaustion.
  • Orphaned Distributed Firewall Rules accumulated in NSX-T policy tables, slowing down policy evaluation cycles across 200+ host clusters.
[WARNING] 2021-10-12 11:45:00 - NSX-T Audit Compliance Scanner
Orphaned Resources Detected:
- 42 Unattached Tier-1 Gateways (No active segment ports)
- 120 Inactive Segment Subnets holding 7,680 IP addresses
- 310 Stale Distributed Firewall Rules referencing deleted AD groups

Manual cleanup tickets took 5 days per pod, wasting thousands of dollars in un-reclaimed cloud capacity.


The Solution

I built an automated Zero-Touch Pod Teardown Workflow in Ansible Tower that executed reverse dependency unbinding and resource reclamation:

  1. Cascade Dependency Deletion: Programmed Ansible tasks to delete Distributed Firewall rules first, followed by Segment interfaces, Tier-1 Gateways, and IPAM subnet releases.
  2. Safety Dry-Run Mode: Added an automated check verifying zero active virtual machine NICs were attached to segment ports prior to deletion.
  3. Idempotent REST API Calls: Executed DELETE requests to the NSX-T Policy API with status code validation.
# roles/nsxt_teardown/tasks/main.yml - Automated Pod Teardown
- name: Verify zero active VMs on segment ports
  uri:
    url: 'https://{{ nsxt_manager }}/policy/api/v1/infra/tier-1s/{{ tenant_id }}/segments/{{ item.name }}/realized-state'
    method: GET
    url_username: '{{ nsxt_user }}'
    url_password: '{{ nsxt_password }}'
  register: realized_state
  failed_when: realized_state.json.state.attachment_count > 0

- name: Delete Tier-1 Gateway via NSX-T Policy API
  uri:
    url: 'https://{{ nsxt_manager }}/policy/api/v1/infra/tier-1s/{{ tenant_id }}'
    method: DELETE
    url_username: '{{ nsxt_user }}'
    url_password: '{{ nsxt_password }}'
    status_code: [200, 204]

Key Takeaway

Always pair deployment automation with automated zero-touch decommissioning pipelines. Automated resource reclamation prevents IP address exhaustion and keeps SDN policy tables clean.


Architecture and decisions: mine. Debugging sessions at odd hours: mine. AI assistance: structure, syntax, first draft. β€” Sachin

SKS

Sachin Kumar Sharma

Associate Director (Infrastructure & Cloud Architecture Strategy) | 20+ Yrs Exp

Architecting resilient multi-cloud enterprise landing zones, SDN overlay fabrics, DevSecFinOps automation pipelines, and autonomous Agentic AI platforms.

πŸ“¬

πŸ“¬ Stay Updated on Tech Releases

Sign up to get notified when I publish new production war stories, agentic AI architecture blueprints, or open-source infrastructure tools.

⚑ Theme Adaptive Shift
Switching layouts matching domain reading affinity...