Deploying NSX With Ansible08 Jun 2016
Here I will describe the steps taken to deploy NSX Manager using the Ansible NSX Module. The NSX Ansible module is written by VMware and is provided opensource on GitHub. To work properly this depends on the NSX RAML Specification, NSX RAML Python Client, vSphere API Python Bindings and the OVF Tool all being installed on the Ansible server.
The following assumes you have a working Ansible installation already, and a vSphere environment to install NSX to. If you don’t yet have these you can see how I performed my Ansible Installation in this earlier blog post.
NSX RAML Specification
As the NSX REST API changes with each release the REST API Markup Language (RAML) specification for NSX is provided as a different branch of the GitHub repository. In my environment I will be using NSX 6.2.2 so first I ensure the git client is installed to my Ansible server and then I use this to take a clone of the correct branch.
NSX RAML Python Client
The NSX RAML python client is series of functions which can be used standalone or in our case called by the Ansible NSX module. To install these we need to ensure the ‘Python Package Manger’ and some other tools are installed and available on our Ansible server.
Once thes pre-requiste components are in place we can then install the NSX RAML python client. Similar to the RAML specification, the client functions are also dependant on version. The version which works with NSX RAML Specification 6.2.2 is Python client 1.0.4. To install this version from Python package manager we use.
If you have NSX Manager already deployed you can create a session to this using the python client. First start python by running
then you can run the commands similar to this to create a session.
you can then see the session by running the following command in python session
VMware vSphere API Python Bindings
As well as the NSX Python client the Ansible NSX Module also depends on the VMware vSphere API Python Bindings (pyVmomi. pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter. This is similarly installed with the python package manager using command like.
The final thing to be installed for the NSX Module to operate correctly is the VMware OVF Tool. The OVF tool for Linux version 4.1.0 is available here, please note a VMware login is required to get this.
Once downloaded to the Ansbile server, we need to ensure it has execute attribute and then execute it to start the install, the commands to do this for the current version 4.1.0 are.
Once the install is running you have to agree to EULA, to get to the end of the text, hold down the Space bar. When prompted Do you agree? type yes.
Once OVF Tool is installed we can use SCP to copy the NSX OVA, VMware-NSX-Manager-6.2.2-3604087.ova, to Ansible server I placed this in folder named /OVAs.
Ansible NSX Module
We already have Git installed for dowlnloading the NSX RAML Specification so we can use this to clone the NSX Ansible repository.
Deploy NSX Manager
The NSX Module comes supplied with some example playbooks for performing common tasks, we’ll first take a copy of the example to deploy NSX Manager
We can then edit the contents to match the variables we plan to deploy in environment. While most of playbook contents are environmental specific varibles its worth noting that we run this module against the Ansible server itself as this is where the OVA and ovftool are located so hosts: value will always be localhost.
Once we have our environmental specific entries set we can execute the playbook with Ansible.
We see this deploys ‘NSX Manager’ and configures the setting specified in the playbook.
Deploy NSX Manager and register with vCenter and SSO
As with any Ansible playbook we can put common variables in a central location and call these from playbooks. An example is provided called answerfile-deployLab.yml. Variable names are overlapped between parts of the NSX Modules, in order that they are unique in the central answer file the names vary but its very easy to match these.
An example of my playbook to deploy NSX Manager and then register this with vCenter and SSO.