News: VMwareGuruz has been  Voted Top 50 vBlog 2018. 

Automation

Automating ESXi Host Deployment in Cisco UCS Infrastructure with Ansible Tower and Bitbucket

Introduction

In modern VMware environments, automating ESXi deployments in Cisco UCS infrastructure is critical to achieve speed, efficiency, and consistency. Using Ansible, integrated with Ansible Tower and Git (Bitbucket) for version control, you can centrally manage your automation workflows and configuration changes.

This blog will guide you through:

  1. Writing playbooks for ESXi deployments.
  2. Versioning templates in Bitbucket.
  3. Integrating with Ansible Tower for centralized execution and management.

Solution Architecture

  1. Bitbucket: Source control to maintain playbooks, configurations, and credentials securely.
  2. Ansible Tower: Centralized automation platform for managing and scheduling jobs.
  3. vCenter & UCS Manager: Targets for automation to configure hardware profiles and deploy ESXi.

Prerequisites

1. Git and Bitbucket Setup

  • A Bitbucket repository with your Ansible playbooks and configuration files.
  • Bitbucket credentials or SSH keys configured for Tower to pull the repository.

2. Ansible Environment

  • Ansible 2.14.x installed.
  • VMware Collection:
    bash
    ansible-galaxy collection install community.vmware --upgrade

3. Ansible Tower Setup

  • Project in Tower linked to the Bitbucket repository.
  • Credentials for vCenter, UCS Manager, and Bitbucket.

Step 1: Maintain Playbooks and Configs in Bitbucket

Create a directory structure in Bitbucket for better organization:

bash
ansible-automation/

├── playbooks/
│ └── deploy_esxi.yml # Playbook for ESXi deployment

├── inventories/
│ └── ucs_esxi_inventory.ini # Inventory for UCS and ESXi hosts

├── vars/
│ └── esxi_configs.yml # Configuration variables

└── README.md

Sample Playbook: deploy_esxi.yml

yaml
- name: Deploy ESXi Hosts on Cisco UCS
hosts: localhost
gather_facts: no
collections:
- community.vmware
vars_files:
../vars/esxi_configs.yml

tasks:
name: Configure UCS Profiles
uri:
url: “https://{{ ucs_manager }}/nuova”
method: POST
body: “<configResolveClass cookie=” classId=’computeBlade’/>”
body_format: xml
validate_certs: no
register: ucs_response

name: Deploy ESXi Hosts in vCenter
vmware_guest:
hostname: {{ vcenter_hostname }}
username: {{ vcenter_username }}
password: {{ vcenter_password }}
validate_certs: no
name: {{ item.name }}
datacenter: “Datacenter”
cluster: {{ item.cluster }}
datastore: {{ item.datastore }}
hardware:
memory_mb: 16384
num_cpus: 4
disk:
size_gb: 100
type: thin
networks:
name: “VM Network”
ip: {{ item.ip }}
netmask: “255.255.255.0”
gateway: “192.168.1.1”
state: poweredon
loop: {{ esxi_hosts }}


Configuration File: esxi_configs.yml

yaml
vcenter_hostname: "vcenter.domain.com"
vcenter_username: "administrator@vsphere.local"
vcenter_password: "password"
ucs_manager: “ucs-manager.domain.com”

esxi_hosts:
{ name: “esxi-01”, ip: “192.168.1.101”, cluster: “UCS-Cluster”, datastore: “datastore1” }
{ name: “esxi-02”, ip: “192.168.1.102”, cluster: “UCS-Cluster”, datastore: “datastore1” }


Step 2: Link Bitbucket Repository in Ansible Tower

  1. Add Bitbucket Credentials in Tower:
    • Navigate to Ansible Tower → Credentials → Add.
    • Type: Source Control
    • Provide username/password or SSH keys for Bitbucket access.
  2. Create a Project in Tower:
    • Go to Projects → Add Project.
    • Name: VMware ESXi Deployment Project.
    • SCM Type: Git.
    • SCM URL:
      arduino
      https://bitbucket.org/yourteam/ansible-automation.git
    • SCM Update Options: Enable “Update Revision on Launch” to pull the latest code from Bitbucket.

Step 3: Create a Job Template

  1. Go to Templates → Add → Job Template.
  2. Fill in the following fields:
    • Name: Deploy ESXi Hosts
    • Inventory: Select your UCS inventory file.
    • Project: Select the Bitbucket-linked project.
    • Playbook: playbooks/deploy_esxi.yml
    • Credentials:
      • vCenter Credentials
      • UCS Manager Credentials
      • Bitbucket SCM Credentials
    • Verbosity: Set to -vvv for detailed logs.
  3. Surveys (Optional):
    Use a Survey to prompt for dynamic inputs such as vCenter hostname, UCS Manager IP, or ESXi Hostnames during job launch.

Step 4: Launch the Job Template

  1. From the Job Templates view, click Launch on the Deploy ESXi Hosts template.
  2. Monitor the Job Output for task execution status.
  3. Upon successful execution, the playbook will:
    • Configure UCS service profiles.
    • Deploy ESXi hosts in the specified vCenter cluster.

Step 5: Automate and Scale with Tower

  1. Schedule Jobs:
    • Automate deployments by scheduling the job template at regular intervals.
  2. Notifications:
    • Integrate notifications via Slack, email, or other services when the job succeeds or fails.
  3. Role-Based Access Control (RBAC):
    • Use Tower’s RBAC to control who can execute, edit, or manage templates and projects.
  4. Monitor and Troubleshoot:
    • Use the Job Events in Tower to identify failures and debug tasks.

Benefits of This Workflow

  1. Centralized Code Management
    • Playbooks and configurations are version-controlled in Bitbucket.
    • Changes can be reviewed and merged via pull requests.
  2. Automated Deployment
    • Ansible Tower automates workflows, reduces manual errors, and improves consistency.
  3. Dynamic Inputs
    • Use Tower Surveys to provide runtime inputs for flexible deployments.
  4. Scalable Infrastructure Management
    • Easily deploy and manage multiple ESXi hosts across UCS environments.

Conclusion

By integrating Ansible, Ansible Tower, and Bitbucket, you can automate and manage ESXi deployments seamlessly in a Cisco UCS environment. The combination of version-controlled templates in Bitbucket and Tower’s centralized execution ensures reliable, scalable, and efficient infrastructure automation.

Take advantage of this workflow to:
Centralize your automation code in Bitbucket.
Orchestrate deployments using Ansible Tower.
Scale effortlessly across large VMware and UCS environments.


Happy Automating! 🚀

If you have questions, feel free to share them in the comments below. Let’s collaborate to take VMware automation to the next level!

 

Related posts
Automation

Automating VM Provisioning for Costico: A Comprehensive Guide

Automation

Automating ESXi Host Deployment in Cisco UCS Infrastructure with Ansible Tower and Bitbucket

Automation

VMware Automation: "Streamlining vCenter Upgrades from 7.x to 8.x with PowerCLI and Ansible"

Automation

VMware Automation: "Mastering VMware Diagnostics with VCF Tool"